ckeditor allowedExtraContent 结束 html 标签

ckeditor allowedExtraContent with closing html tag

我在配置我的 ckEditor 时遇到问题。

配置看起来像这样:

<script>
  $( document ).ready( function() {
    var ckeditor = CKEDITOR.replace( 'myTest', {
            allowedContent: true
            extraAllowedContent : 'foo[*]{*}'
</script>

HTML 是:

<textarea id="myTest">
  <foo>balabalabal</foo>
  <foo attr="value"/>
</textarea>

当我在浏览器中查看结果时,如果缺少第二个 foo 标记, 我怎样才能同时保留它们?

您需要记住 CKEditor 是一个 HTML 编辑器并且没有 <foo> 标签。此外,您还创建了一个封闭 <foo></foo> 标签和一个自封闭 <foo /> 标签。您不能将此类内容加载到 CKEditor 中。

请注意,可以稍微调整 CKEditor 以接受非 HTML 标签。这可以通过扩展 CKEDITOR.dtd 对象来实现。

CKEDITOR.dtd.foo = { '#': 1 };
CKEDITOR.dtd.body.foo = 1;
CKEDITOR.dtd.$block.foo = 1;

这将允许 foo 个标签作为 body 的子标签。 foo 标签将只允许包含文本内容 ('#'),并将被视为块标签。