在 CKEditor 中,配置中有 allowedContent
和 extraAllowedContent
选项。我了解 allowedContent
如何允许您说出 ACF 将留下哪些标签和属性,但为什么会有 allowedContent
和 extraAllowedContent
?他们不做同样的事情吗?
我发现的一件事是,当想要允许 iframe 时,只有将 iframe[*]
放入 extraAllowedContent
中,它似乎才有效;如果将它放在 allowedContent
中,它就不起作用。
为什么?有什么区别?
最佳答案
设置allowedContent
手动指示编辑器完全忽略启用插件指定的允许标记(例如列表插件“注册”<ul>
和 <li>
标签)。它可能会导致从 CKEditor 中删除功能。例如,如果您使用标准预设并且只允许 iframe[*]
,那么大多数按钮将从工具栏“消失”(如粗体、列表、表格),因为您不再允许像 <strong>
这样的元素。 , <ul>
, <li>
等等。
extraAllowedContent
,顾名思义,允许您扩展 CKEditor 默认允许的允许标签/属性列表。 CKEditor 默认支持什么直接取决于您启用了哪些功能。
以下链接解释得非常好:https://docs.ckeditor.com/ckeditor4/docs/#!/guide/dev_acf
One thing I have found is when wanting to allow iframes it only seems to work if you put iframe[*] in extraAllowedContent; it does not work if you put it in allowedContent.
看起来你在代码中犯了一个错误,因为我刚刚检查了那个案例并且它按预期工作(iframe 元素保留在内容中,所有其他标记都被删除,大部分工具栏按钮都消失了)。
最后但并非最不重要的一点是,考虑向 CKEditor 添加另一个插件以正确处理编辑 iframe(https://ckeditor.com/cke4/addon/iframe),而不是仅仅启用带有 extraAllowedContent 的 iframe 元素。如果你将它添加到你的构建中,它会自动允许 <iframe>
元素。
关于javascript - CKEditor 中的 allowedContent 和 extraAllowedContent 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46948341/