ckeditor strips <span> and style attributes

淺唱寂寞╮ 提交于 2019-12-04 08:12:43

If you are using the CKeditor module then there is an option in Advanced Options that is also mentioned in the module homepage where you should set:

config.allowedContent = true;

None of the above solutions worked for me. What I found was that CKEditor was removing empty <span> tags from the HTML. For example:

<div class="section-heading">
    <span class="sep-holder-l"><span class="sep-line"></span></span>
    <h4>Section Header</h4> 
    <span class="sep-holder-r"><span class="sep-line"></span></span>
</div>

Would yield:

<div class="section-heading">
    <h4>Section Header</h4> 
</div>

However, if I added a non-breaking space in the innermost <span>, CKEditor didn't edit the HTML:

<div class="section-heading">
    <span class="sep-holder-l"><span class="sep-line">&nbsp;</span></span>
    <h4>Section Header</h4> 
    <span class="sep-holder-r"><span class="sep-line">&nbsp;</span></span>
</div>

Hopefully that helps someone out there!

In Drupal 7 there's no automatic synchronization between CKEditor's filter (called the Advanced Content Filter) and Drupal's filter. As I understand you configured latter one, but not the first one. See config.extraAllowedContent.

Grasshopper

CKEditor 4.+ will remove any empty tags it finds which are in CKEDITOR.dtd.$removeEmpty as part of the HTML parsing process. See this answer for a hack to avoid it.

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