【问题标题】:Stop CKEditor 4 from adding additional HTML tags阻止 CKEditor 4 添加额外的 HTML 标签
【发布时间】:2021-09-28 16:32:18
【问题描述】:

CKEditor 4 添加额外的 HTML 标记时遇到问题。我已经使用 v3 几年了,没有任何问题,并且我已经构建了自己的插件,所以我不是一个完整的新手,但这让我很难过。例如下面的 HTML 块:

<section class="component2">
    <div class="">
        <div class="component2__row">
            <a class="component2__item component2__item--primary" href="#">
                <img class="component2__item__image" src="http://MyServer/webmedia/Images/Components/component2/image-1.jpg" alt="IMG"/>
                <h4 class="component2__item__title">Light Vehicle</h4>
            </a>
        </div>
    </div>
</section>

保存为:

<section class="component2">
    <div>
        <div class="component2__row">
            <a class="component2__item component2__item--primary" href="#">
                <img alt="IMG" class="component2__item__image" src="http://MyServer/webmedia/Images/Components/component2/image-1.jpg" />
            </a>
            <h4 class="component2__item__title">
                <a class="component2__item component2__item--primary" href="#">Light Vehicle</a>
            </h4>
            <a class="component2__item component2__item--primary" href="#"> </a>
        </div>
    </div>
</section>

有什么想法吗? (注意例如附加的锚标记!)HTML中有什么东西吗 它不喜欢?我可以使用 config.js 中的设置吗?

谢谢

【问题讨论】:

    标签: html tags ckeditor config ckeditor4


    【解决方案1】:

    如果其他人偶然发现了这个,我会解决它。因为它已经是我的默认设置(从 v3 开始),所以我已经尝试过:

    config.allowedContent = true;
    

    我详细阅读了文档,甚至尝试编辑 dtd 以允许标题位于 div 和锚点中:

    CKEDITOR.dtd['div']['h'] = 1;
    CKEDITOR.dtd['a']['h'] = 1;
    

    一切都无济于事。最终我放弃并用&lt;span&gt; 替换了我的示例中的&lt;h4&gt; 标签并相应地设置了它的样式。这有效,CKEDITOR 现在让我的源 HTML 保持不变。令人恼火的是,没有一个功能可以让您告诉编辑器“看,我知道我的 HTML 是有效的,别管它,我会处理任何后果。”

    【讨论】:

      猜你喜欢
      • 2011-02-05
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 2016-12-19
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      相关资源
      最近更新 更多