KMK
KMK

Reputation: 1509

TinyMCE executes HTML tags - how to stop it?

I'm trying to include simple code samples in the TinyMCE editor. It looks fine when I'm writing it and when it is saved in the MySQL database. But when loading it in the TinyMCE editor once again the HTML-tags seems to be executed, even though they are saved as HTML names and not the actual tags.

For example if I write

<b>test</b>

In the database this was exactly what was stored, but when loading it in the TinyMCE editor, it now looks like

<b>test</b>

And if this is saved and loaded one more time it turns into

test

So it seems like TinyMCE is executing the tags, even though they are not actual tags to begin with. Does anyone know why this is happening?

I have tried to add the pre-tag and code-tag around the code, but it seems to be ignored by TinyMCE. I've also tried to add

preformatted : true,
verify_html : false,

to the TinyMCE init-function.

Any help would be greatly appreciated. Thanks.

Upvotes: 1

Views: 3443

Answers (2)

SG 86
SG 86

Reputation: 7078

From v3 documentation:

Removed in 3.4

This option enables or disables the built-in clean up functionality. TinyMCE is equipped with powerful clean up functionality that enables you to specify what elements and attributes are allowed and how HTML contents should be generated. This option is set to true by default, but if you want to disable it you may set it to false.

Notice: It's not recommended to disable this feature.

It might be worth mentioning that the browser usually messes with the HTML. The clean up not only fixes several problems with the browsers' parsed HTML document, like paths etc., it also makes sure it is a correct XHTML document, with all tags closed, the " at the right places, and things like that.

Example of usage of the cleanup option:

tinyMCE.init({
        cleanup : true
});

Upvotes: 2

KMK
KMK

Reputation: 1509

I found out this is not a TinyMCE problem, this is just how textareas work. I used the PHP function htmlspecialchars() and everything is now working as intended.

<textarea><?=htmlspecialchars($content)?></textarea>

Upvotes: 1

Related Questions