You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Jodit移除Font Awesome标签?

解决Jodit切换源代码模式移除Font Awesome标签的问题
  • 调整HTML清理白名单与标签替换规则
    Jodit默认会将<i>标签替换为<em>,还会过滤无内容的标签。初始化编辑器时,通过配置明确允许<i>标签保留class属性,并关闭自动替换行为:

    const editor = new Jodit('#editor', {
      whitelist: {
        i: ['class']
      },
      replaceTags: {
        i: false
      }
    });
    
  • 排除空标签的自动清理
    若你的<i>标签无文本内容,Jodit的默认规则会清理空元素。可以配置cleanEmptyTags,将<i>排除在清理列表外:

    const editor = new Jodit('#editor', {
      cleanEmptyTags: ['div', 'p', 'span'] // 仅清理指定空标签,不包含<i>
      // 若需完全关闭空元素清理,可设为false,但可能保留多余空标签
      // cleanEmptyTags: false
    });
    
  • 自定义HTML清理规则(进阶)
    若上述配置仍不生效,可直接修改htmlCleaner的规则,确保Font Awesome标签被完整保留:

    const editor = new Jodit('#editor', {
      htmlCleaner: {
        allowTags: ['i'],
        allowAttributes: {
          i: ['class']
        },
        removeEmptyTags: false
      }
    });
    

内容的提问来源于stack exchange,提问作者Friendly Genius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 17:15:58