编辑器添加xss 并保留style样式处理

2023-06-27  本文已影响0人  多记录多学习
import xss from 'xss';
export default new xss.FilterXSS({
  whiteList: {
    // 允许的标签和属性
    style: ['*'],
  },
  onTag: (tag, html) => {
    // 判断需要筛除的标签
    const filterTag = ['script', 'iframe', 'alert'];
    if (filterTag.includes(tag)) {
      return ''; // 返回空字符串来移除标签
    }
    return html; // 保留其他标签
  },
});
上一篇 下一篇

猜你喜欢

热点阅读