// html特殊字符转义
const special = html => {
html = html.replace(/ /gm, ' ');
html = html.replace(/</gm, '<');
html = html.replace(/>/gm, '>');
html = html.replace(/Ø/gm, 'Ø');
html = html.replace(/°/gm, '°');
html = html.replace(/"/gm, '"');
html = html.replace(/·/gm, '·');
html = html.replace(/&/gm, '&');
html = html.replace(/¥/gm, '¥');
return html;
};
// 移除样式字段
const removeCSS = html => {
html = html.replace(/style=["'][^"']*['"]/ig, '');
html = html.replace(/<style>[^<]*</style>/ig, '');
return html;
};
// 替换标签
const stripHTML = html => {
html = removeCSS(html);
html = html.replace(/\n|
/gm, '<br>');
html = html.replace(/(</p>)|(<tr>)|(</table>)|(<ol>)|(</ol>)|(<ul>)|(</ul>)|(<div>)|(</div>)/gm, '<br>');
html = html.replace(/(<b[s]*>)|(</b[s]*>)/ig, '');
html = html.replace(/(<li>)/gm, '');
html = special(html);
let regex = /<[^img | ^br].*?>/ig;
html = html.replace(regex, '');
html = html.replace(/(( *
*
s*)+)/gm, '');
html = html.trim();
html = html.replace(/(<br[s]*[/]?>[s]*)+/ig, '<br>');
html = html.replace(/(^<br>)|(<br>$)/ig, '');
return html;
};