Welcome to Geeklog Wednesday, December 12 2018 @ 10:47 pm EST

Geeklog Forums

CKEditor removing empty tags automatically


Status: offline

alb3rt

Forum User
Chatty
Registered: 30/10/06
Posts: 52
Location:Mexico City
I insert html content contain the <i> elements. I do this with the CKEditor. Everything works when I add "&nbsp;" and the content shows up on the webpage. But when i want to edit the previously inserted content, the <i> elements are missing.

For example:

PHP Formatted Code
<i class="fa fa-map-marker fa-2x"> </i>


I tried add this lines to the config.js (/public_html/editors/ckeditor/ckeditor.js) but not works

PHP Formatted Code
CKEDITOR.dtd.$removeEmpty['i'] = false;


PHP Formatted Code
config.protectedSource.push(/<i[^>]*><\/i>/g);


PHP Formatted Code
CKEDITOR.dtd.$removeEmpty['b'] = false;

D Web Studio - www.d-webstudio.net

Status: offline

Laugh

Site Admin
Admin
Registered: 27/09/05
Posts: 1317

Status: offline

alb3rt

Forum User
Chatty
Registered: 30/10/06
Posts: 52
Location:Mexico City
I solved it. It is necessary to add the following lines to the file (~/editors/ckeditor/config.js) between ... CKEDITOR.editorConfig = function( config ) { ... }
PHP Formatted Code

config.protectedSource.push(/<i[^>]*><\/i>/g);  // <i></i>
config.protectedSource.push(/<span[^>]*><\/span>/g);  //<span></span>
 


And clean the browser cache (Important).
D Web Studio - www.d-webstudio.net

Phil_69

Anonymous
I had the same problem with the <a> tag and resolved it. But in my case, the closing tag was on the next line. So I had to change the filter :
PHP Formatted Code
config.protectedSource.push(/<i[^>]*><\/i>/g);

to
PHP Formatted Code
config.protectedSource.push(/<i[^>]*>[\s]*<\/i>/g);

For the others tags this hack seems to work :
PHP Formatted Code
$j.each(CKEDITOR.dtd.$removeEmpty, function (i, value) {
    CKEDITOR.dtd.$removeEmpty[i] = false;
});

But not for the <a> tag !

Status: offline

alb3rt

Forum User
Chatty
Registered: 30/10/06
Posts: 52
Location:Mexico City
This work for me:

PHP Formatted Code
<a>&nbsp;</a>


And in gl 2.2.0 I use:

PHP Formatted Code
config.protectedSource.push(/\[i[\s\S]+?\/i\]/g);
 

D Web Studio - www.d-webstudio.net

All times are EST. The time is now 10:47 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content