Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ckeditor strips <span> and style attributes

I have a Drupal 7 site using ckeditor 4.2. I've created a basic page node and put a span inside an h2 heading in the body. I hard coded it in the html view. It looks fine but if I go back to edit the page, my has gotten stipped out of the html and also any style="" I've put into the html also. I've looked at the ckeditor config and text-formats. I've set the only formats allowed to be text and full html so I'm not using filtered at all. What gives? I've used the editor many times before but probably not this version.

like image 734
james Avatar asked Aug 21 '13 04:08

james


4 Answers

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;

CKeditor configuration

like image 126
TheodorosPloumis Avatar answered Oct 21 '22 21:10

TheodorosPloumis


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!

like image 23
Kevin Howard Goldberg Avatar answered Oct 21 '22 20:10

Kevin Howard Goldberg


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.

like image 1
Reinmar Avatar answered Oct 21 '22 21:10

Reinmar


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.

like image 1
Grasshopper Avatar answered Oct 21 '22 21:10

Grasshopper