TinyMCE Removes Non-breaking Spaces

A note from A Beautiful Site’s founder: We developed Surreal to be easy for you and your clients. If you’re a web designer, you should take a look at the simple, hosted CMS that’s changing the way content is managed. Surreal integrates in moments and is trusted by over 18,000 websites. Try it out for free and let us know what you think! Visit Website »

There are two reasons that TinyMCE might be removing non-breaking space entities ( ) from your HTML source code.  The first one is a common mistake people make when populating textareas.  This is covered in the TinyMCE FAQ, so there’s really no need to elaborate on this particular reason.

The second reason, however, is a bit more complicated, and only occurs if you have the entity_encoding property set to raw:

tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	...
	entity_encoding: 'raw'
});

If your configuration looks similar to this, you’ll most likely see all of your   entities get converted to regular spaces when you switch between HTML view and WYSIWYG view.  The easy solution would be to set entity_encoding to either named or numeric.  Fortunately, if you’re using ISO-8859-1 for your character encoding, you’re all set.  Unfortunately, if you’re using UTF-8 you’ll need to take an additional step to prevent many of your non-English characters from appearing as HTML entities.

The solution is simple.  Set your entity_encoding to named and overwrite the entities property:

tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	...
	entity_encoding: 'named',
	entities: '160,nbsp'
});

The above is the same thing as using raw entity encoding, except that your non-breaking space entities will be preserved.

If you enjoyed this article, please share it with a friend!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>