CKeditor, colour of text seems to be not retained although HTML is correct, how to resolve?

拜拜、爱过 提交于 2019-12-12 05:36:14

问题


I am using CKEditor 4.4.5.

Users use the text colour icon to change the colour of a word which works fine. When one checks the underlying HTML, it shows:

<p><span style="color:#FF0000">test&nbsp;</span></p>

However when clicks the "source" icon again to return to the standard non HTML view, the colouring has gone, although the underlying HTML is still correct. If you take this HTML and render it in a browser it will work correctly. So it seems that CKEditor is not able to render text colour correctly, unless freshly changed using the text colour icon.

We had customers thinking that the colour had not changed, and then trying to fix the issue in the HTML, which resulted in the total corruption of the HTML due to human error.

Is this a bug, or am I missing something?

Thanks.


回答1:


As for CKEditor it might so happen that Advanced Content Filter will strip undesired tags / attributes.

If you don't have colorbutton plugin, CKEditor will strip this span (see standard demo).

You have 2 simple solutions:

Add colorbutton plugin.

Simply add to your config:

    config.extraPlugins = 'colorbutton';

Add ACF proper rule.

    config.extraAllowedContent = 'span{color}';

For more informations about ACF see Content Filtering (ACF).



来源:https://stackoverflow.com/questions/27984096/ckeditor-colour-of-text-seems-to-be-not-retained-although-html-is-correct-how

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!