CKEditor剥离内联属性

tia*_*ang 25 html ckeditor strip-tags

我已经使用CKEditor一段时间了,它工作得很好.我几乎已经摆脱了我遇到的任何问题,但这个我似乎无法弄清楚.当我添加内嵌属性例如元件style = "color: #ff0;"上的<p></p>标签它们剥离出来时,我从所见即所得切换到源视图.没有保存或提交,并且ckeditor已添加到我的网站,这是我自己的脚本.关于什么会导致这个的任何想法.我能找到的所有搜索结果都对应于Drupal中发生的这种情况,但Drupal似乎是问题而不是所有实例中的编辑器.再次感谢!

ole*_*leq 34

感觉就像你正在使用高级内容过滤器(ACF)附带的CKEditor 4.1+ .如果是这样,您需要指定config.allowedContent配置它以使您的工作正常.您可能也有兴趣config.extraAllowedContent.

有关详细信息,请参阅此答案.


Wik*_*alc 10

对于任何寻找关于如何在CKEditor中启用其他标记而不完全禁用ACF的简单示例的人,这里有一个简短的片段:

CKEDITOR.replace( 'editor1', {
    extraAllowedContent: 'style;*[id,rel](*){*}'
} );
Run Code Online (Sandbox Code Playgroud)

extraAllowedContent在这里启用<style>元素,允许所有(*是通配符)已经允许的元素的两个附加属性(在方括号中),允许使用任何类名称(*)并允许使用任何内联样式{*}


小智 5

嗨,你可以很容易地停止ACF.默认你的混淆是---

function ckeditor($name,$value='',$height=300){
    return '<textarea name="'.addslashes($name).'">'.htmlspecialchars($value).'</textarea>
<script>$(function(){CKEDITOR.replace("'.addslashes($name).'",{});});</script>';
} 
Run Code Online (Sandbox Code Playgroud)

只需在花括号中添加:

allowedContent: true
Run Code Online (Sandbox Code Playgroud)

现在您的配置将是:

function ckeditor($name,$value='',$height=300){
    return '<textarea name="'.addslashes($name).'">'.htmlspecialchars($value).'</textarea>
<script>$(function(){CKEDITOR.replace("'.addslashes($name).'",{allowedContent: true});});</script>';
}
Run Code Online (Sandbox Code Playgroud)


Rak*_*ati 5

我遇到了同样的问题,下面的答案解决了我的问题:

config.allowedContent = true;
config.extraAllowedContent = '*(*);*{*}';
config.extraAllowedContent = 'span;ul;li;table;td;style;*[id];*(*);*{*}';
Run Code Online (Sandbox Code Playgroud)