小程序富文本特殊字符转移
小程序富文本特殊字符转义
function escapeHtml(str) {
var arrEntities = {
'lt': '<',
'gt': '>',
'nbsp': ' ',
'amp': '&',
'quot': '"',
'middot': '·',
'amp': '&',
'brvbar': '¦',
'mdash': '—',
'ndash': '–',
'ge': '≥',
'le': '≤',
'laquo': '«',
'raquo': '»',
'deg': '°',
'bull': '•',
'macr': '¯',
'#64': '@'
};
return str.replace(/&(lt|gt|nbsp|amp|quot|middot|amp|brvbar|mdash|ndash|ge|le|laquo|raquo|deg|bull|macr|#64);/ig, function (all, t) { return arrEntities[t]; }).replace('<section', '<div').replace('<img', '<img style="max-width:100%;height:auto" ');
}
浙公网安备 33010602011771号