Html CKEditor 去除内联属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15753956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CKEditor strips inline attributes
提问by tiantang
I have been using CKEditor for some time and it has worked great. I've pretty much gotten rid of any problems that ive had but this one i cant seem to figure out. When i add inline attributes to elements for instance style = "color: #ff0;"
on a <p></p>
tag they are stripped out when i switch from wysiwyg to source view. No saving or submission is done and ckeditor is has been added to my site which is my own script. Any ideas as to what would cause this. All of the search results i can find correspond to this happening in Drupal but Drupal seems to be the problem not the editor in all instances. Thanks again!
我已经使用 CKEditor 一段时间了,效果很好。我几乎摆脱了我遇到的任何问题,但我似乎无法弄清楚这个问题。当我向元素添加内联属性时,例如style = "color: #ff0;"
在<p></p>
标签上,当我从所见即所得切换到源视图时,它们会被删除。没有保存或提交完成,ckeditor 已添加到我的网站,这是我自己的脚本。关于什么会导致这种情况的任何想法。我能找到的所有搜索结果都与 Drupal 中发生的这种情况相对应,但 Drupal 似乎是所有情况下都不是编辑器的问题。再次感谢!
回答by oleq
It feels like you're using CKEditor 4.1+ that comes with Advanced Content Filter (ACF). If so, you need to specify config.allowedContent
and configure itto get your things working. You may also be interested in config.extraAllowedContent
.
感觉就像您正在使用高级内容过滤器 (ACF)附带的 CKEditor 4.1+ 。如果是这样,您需要指定config.allowedContent
和配置它以使您的工作正常工作。您可能还对config.extraAllowedContent
.
See this answerfor more details.
有关更多详细信息,请参阅此答案。
回答by Wiktor Walc
For anyone looking for a simple sample on how to enabled additional markup in CKEditor without disabling ACF completely, here is a short snippet:
对于正在寻找如何在 CKEditor 中启用附加标记而不完全禁用 ACF 的简单示例的任何人,这里是一个简短的片段:
CKEDITOR.replace( 'editor1', {
extraAllowedContent: 'style;*[id,rel](*){*}'
} );
extraAllowedContenthere enables the <style>
element, allows two additional attributes (in square brackets) for all (*
is a wildcard) already allowed elements, allows usage of any class names (*)
for them and allows usage of any inline styles {*}
extraAllowedContent此处启用<style>
元素,允许所有(*
是通配符)已经允许的元素的两个附加属性(在方括号中),允许(*)
为它们使用任何类名并允许使用任何内联样式{*}
回答by Chayon Shaah
hi you can stop ACF easily . by default your configaration is---
嗨,您可以轻松停止 ACF。默认情况下,您的配置是---
function ckeditor($name,$value='',$height=300){
return '<textarea name="'.addslashes($name).'">'.htmlspecialchars($value).'</textarea>
<script>$(function(){CKEDITOR.replace("'.addslashes($name).'",{});});</script>';
}
just add this in the curly brackets:
只需将其添加到大括号中:
allowedContent: true
now your configuration will be:
现在您的配置将是:
function ckeditor($name,$value='',$height=300){
return '<textarea name="'.addslashes($name).'">'.htmlspecialchars($value).'</textarea>
<script>$(function(){CKEDITOR.replace("'.addslashes($name).'",{allowedContent: true});});</script>';
}
回答by Rakhi Prajapati
I faced the same issue and below answer solved my problem:
我遇到了同样的问题,下面的答案解决了我的问题:
config.allowedContent = true;
config.extraAllowedContent = '*(*);*{*}';
config.extraAllowedContent = 'span;ul;li;table;td;style;*[id];*(*);*{*}';
回答by st'sahib
I had the same problem, that ck was stripping not only some attributes, but whole elements when pasting a block element, inside a block element (div with some attributes pasted inside a p) while using this method:
我遇到了同样的问题,在使用此方法时,ck 在粘贴块元素时不仅剥离了某些属性,而且剥离了整个元素,在块元素内(在 ap 内粘贴了一些属性的 div):
editor.insertHtml(html);
what solved the problem was using this workaround instead:
解决问题的是使用此解决方法:
editor.insertElement(CKEDITOR.dom.element.createFromHtml(html));