Subject: CKEditor removing empty tags automatically

Posted on: 07/12/17 01:51am
By: alb3rt

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;

Re: CKEditor removing empty tags automatically

Posted on: 07/12/17 06:58am
By: Laugh

Do the solutions on any of these pages work?

https://stackoverflow.com/questions/18261198/ckeditor-removing-empty-span-automatically

https://drupal.stackexchange.com/questions/198783/ckeditor-strips-i-tags

Re: CKEditor removing empty tags automatically

Posted on: 09/12/17 02:52am
By: alb3rt

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).

Re: CKEditor removing empty tags automatically

Posted on: 06/11/18 03:58am
By: 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 !

Re: CKEditor removing empty tags automatically

Posted on: 09/11/18 05:52pm
By: alb3rt

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);
 

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=96661