Html ckeditor 自动删除空跨度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18261198/
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 removing empty span automatically
提问by air
i am using ckeditor and i have vary strange issue.
我正在使用 ckeditor 并且我有各种奇怪的问题。
it remove automatically empty <span>
for example
<span>
例如,它会自动删除为空
<span class="new-class"></span>
removed automatically.
自动删除。
i am searching for solution for last 2 days but no success. i try to put following code in
我正在寻找过去 2 天的解决方案,但没有成功。我尝试将以下代码放入
config.js
配置文件
CKEDITOR.config.allowedContent = true;
but no success.
但没有成功。
i also add following code in html where i use ckeditor but no success.
我还在 html 中添加了以下代码,其中我使用了 ckeditor 但没有成功。
<script>
var editor = CKEDITOR.replace( 'editor1', {
allowedContent: true,
} );
</script>
thanks
谢谢
采纳答案by Reinmar
You'll find two valid answers in this question: CKEditor strips <i> Tag
你会在这个问题中找到两个有效的答案:CKEditor strips <i> Tag
One says it's not possible to keep them if you want to see them in the editor and second says that you can prevent them from deleting, but you'll hide them.
一个说如果你想在编辑器中看到它们就不可能保留它们,第二个说你可以防止它们被删除,但你会隐藏它们。
回答by Patrick
I am using Django CMS 3, CKEditor 4.3 and I got the same problem using twitter bootstrap glyphicon. Looking at : http://ckeditor.com/forums/Support/Prevent-removal-of-empty-span-tags#forum-topic-top.
我正在使用 Django CMS 3、CKEditor 4.3,我在使用 twitter bootstrap glyphicon 时遇到了同样的问题。查看:http: //ckeditor.com/forums/Support/Prevent-removal-of-empty-span-tags#forum-topic-top。
To allow empty span tag, I have added at the end of ckeditor/config.js
为了允许空的span标签,我在ckeditor/config.js的末尾添加了
CKEDITOR.dtd.$removeEmpty.span = 0;
回答by Jonathan Carter
I came across this thread with the same problem and thought I'd post my solution. I didn't want CKEditor to remove any blank elements. Add the following to the bottom of your config.js file:
我遇到了这个问题,并认为我会发布我的解决方案。我不希望 CKEditor 删除任何空白元素。将以下内容添加到 config.js 文件的底部:
$.each(CKEDITOR.dtd.$removeEmpty, function (i, value) {
CKEDITOR.dtd.$removeEmpty[i] = false;
});
回答by Picard
the only option that works for me is to add:
对我有用的唯一选择是添加:
config.extraAllowedContent = 'span(*)';
in the config.js, inside the:
在 config.js 里面:
CKEDITOR.editorConfig = function( config ) {
section the '' (asterisk) allows all classes inside the span tag, to allow only selected class names just add them instead of the '', separated by ','
' '(星号)部分允许 span 标签内的所有类,只允许选择的类名添加它们而不是 '',用 ',' 分隔
回答by skh
This was annoying, but with help across a whole bunch of pages, i'll collate what I had found that works here;
这很烦人,但在一大堆页面的帮助下,我会整理我在这里发现的有用的东西;
(I'm using CKEditor 4.4.1 with the inlinesave editor, but this should work with any plugin)
(我将 CKEditor 4.4.1 与 inlineave 编辑器一起使用,但这应该适用于任何插件)
in the core/filter.jsfile
在 core/ filter.js文件中
change:
改变:
var allowedContent = editor.config.allowedContent;
to:
到:
var allowedContent = true;
( it's advised against this, so make sure you check what the user is saving ;-) )
(建议不要这样做,因此请确保检查用户正在保存的内容;-))
And then in the core/dtd.jsfile
然后在 core/ dtd.js文件中
near the bottom is a $removeEmpty:
which holds a list of the elements that it chooses to ignore if they are set to 1.. Find the span and set it from 1 to 0 (span: 0
)
靠近底部的是 a $removeEmpty:
,它包含一个元素列表,如果它们设置为 1,它会选择忽略这些元素。找到跨度并将其设置为 1 到 0 ( span: 0
)
And if you have the "glyphicons" plugin added to the config.plugins
in config.jsyou should be able to add them, see them in the editor, and once saved, it shall still be there! :-)
如果你config.plugins
在config.js 中添加了“glyphicons”插件,你应该能够添加它们,在编辑器中看到它们,一旦保存,它仍然会在那里!:-)
Hope this helps
希望这可以帮助
回答by progfan
There are two problems here:
这里有两个问题:
1) <span>
s are discarded because they are not allowed contents.
1) <span>
s 被丢弃,因为它们是不允许的内容。
2) <span>
s are discarded because they are empty.
2) <span>
s 被丢弃,因为它们是空的。
To fix the issue not only do you need to have non-empty <span>
s, but also you need config.extraAllowedContent = 'span(selector1,selector2,...,selectorN)'
in your configuration file.
要解决此问题,您不仅需要非空的<span>
s,而且config.extraAllowedContent = 'span(selector1,selector2,...,selectorN)'
您的配置文件中也需要。
As a side note, I recommend against config.allowedContent
because that would allow just about anything.
作为旁注,我建议反对,config.allowedContent
因为这将允许任何事情。