CKeditor剥离字体标记而不是转换为span [英] CKeditor stripping font tags instead of converting to span

查看:632
本文介绍了CKeditor剥离字体标记而不是转换为span的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CKeditor实例(版本4.1.2),其工具栏中包含字体,大小,文本和背景颜色按钮,全部默认。



替换从数据库中加载其内容的< textarea>



当加载的html包含元素:

 < h3>< font color =red>大红色标题< / font>< / h3> ; 

CKeditor只是剥离标签,留下:

 < h3>大红标题< / h3>然而,我的期望(根据文档),它应该将其转换为:

>

 < h3>< span style =color:red>大红标题< / span>< / h3> 

(它同样以大小和面属性贴上标签)。



我没有更改 allowedContent colorButton_foreStyle 这应该对这个问题有任何影响。我已经尝试删除所有自定义配置(保留编辑器的绝对默认实例),它仍然发生。



任何人都可以解释为什么会发生这种情况,修复它?



感谢。






EDIT :在CKeditor源中设置 colorButton_foreStyle 的默认值:

  CKEDITOR.config.colorButton_foreStyle = {
元素:'span',
styles:{'color':'#(color)'},
覆盖: {element:'font',attributes:{'color':null}}]
};

...这就是为什么我预期它会自动转换字体标签..?

解决方案

CKEditor没有默认定义的所有可能的转换。



docs.ckeditor.com/#!/guide/dev_advanced_content_filter-section-4rel =nofollow>高级内容过滤指南 - 内容转换


目前,我们只为少数编辑器功能定义了内容转换,但在未来的版本中它们的数量会增加。


所以,有两个解决方案:


  1. 如果你想保留字体标记,然后通过定义 <$来扩展高级内容过滤器设置c $ c> config.extraAllowedContent 并更改字体插件设置,如 HTML输出示例

  2. 字体标签转换为其较新的等效字体,然后可以添加新的转换。详情请参阅 filter#addTransformations doc。


I have a CKeditor instance (version 4.1.2) with font, size, text and background color buttons in its toolbar, all completely default.

It's created by replacing a <textarea> whose contents are loaded from a database.

When the loaded html contains elements such as:

<h3><font color="red">Big Red Heading</font></h3>

CKeditor is simply stripping away the tags, to leave:

<h3>Big Red Heading</h3>

Whereas, my expectations (according to the docs) were that it should convert this to:

<h3><span style="color:red">Big Red Heading</span></h3>

(It strips tags with size and face attributes also, just the same way).

I haven't changed allowedContent or colorButton_foreStyle, or any other config setting that ought to have any effect on this issue. I've tried removing all custom config (leaving an absolutely default instance of the editor), and it still happens.

Can anyone explain why this might be happening, and how to fix it?

Thanks.


EDIT: The default value of colorButton_foreStyle is set like this in the CKeditor source:

    CKEDITOR.config.colorButton_foreStyle = {
        element: 'span',
        styles: { 'color': '#(color)' },
        overrides: [ { element: 'font', attributes: { 'color': null } } ]
    };

...which is why I expected it would automatically convert font tags..?

解决方案

CKEditor hasn't got all possible transformations defined by default. There is a set of them and it will be enlarged in the future, but this specific one wasn't defined yet.

From Advanced Content Filter guide - content transformations:

Currently, we have defined content transformations for only a handful of editor features, but their number will increase in future releases.

So, there are two solutions:

  1. If you want to keep your font tags, then extend the Advanced Content Filter settings by defining config.extraAllowedContent and change the font plugins settings like in HTML output sample.
  2. If you want to automatically transform your font tags to their newer equivalents, then you can add a new transformations. Read more in filter#addTransformations doc.

这篇关于CKeditor剥离字体标记而不是转换为span的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆