Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent tinymce from stripping empty tags from input?

Tags:

tinymce

I have read loads of posts on various forums and here on SO, and still seem unable to prevent tinymce from stripping empty tags from the end of an editable block.

E.g. I input this:

<a href="blah">zzz</a> <div class="floatClearer" style=""></div> 

..and upon round trip (in and out of HTML mode), tinymce strips off the entire <div class="floatClearer" style=""></div>.

As per various bits of advise I found, I tried these things, and more:

  • remove the minus sign in front of div in my valid_elements,

...and these config. options:

  • verify_html : false,
  • extended_valid_elements : "div*",
  • extended_valid_elements : "div[*]",

ALL to no avail. is there any way to prevent that stripping action? There are other places I need empty tags (not just in this one example), so please, if you can, let me know an answer specific to my question, as opposed to suggesting I not use empty tags.

like image 202
govinda Avatar asked May 06 '12 01:05

govinda


2 Answers

There was a bug in TinyMCE, and now it's fixed (in v3.5.2). Thanks to @Thariama!

For future searchers: Use the verify_html option.

This option enables or disables the element cleanup functionality. If you set this option to false, all element cleanup will be skipped but other cleanup functionality such as URL conversion will still be executed.

Example of usage:

tinyMCE.init({     ...     verify_html: false }); 
like image 146
naXa Avatar answered Oct 07 '22 16:10

naXa


As I do too have troubles, I am adding my brick - on top of Cliff Ribaudo answer.

So I recommend using &nbsp; inside the empty tag which won't be stripped and won't be visible, not even by search engines.

Doing like so have not been stripped on my tinyMCE: <div class="someclass">&nbsp;</div>

like image 22
antoni Avatar answered Oct 07 '22 14:10

antoni