Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Stop TinyMCE modifying markup when HTML is placed in-between pre/code tags


Go to End


1749 Views

Avatar
_Matt

Community Member, 29 Posts

26 January 2015 at 11:27pm

Edited: 26/01/2015 11:30pm

I'm trying to stop TinyMCE modifying my markup. If I put HTML inside a `pre` or `code` tag it removes the `pre` and `code` tags and leaves just the HTML.

So this:

<pre><code class="language-html"><div class="person person--female">
    <div class="person__hand person__hand--left person--female__hand"></div>
</div></code></pre>

Becomes this:

<div class="person person--female">
    <div class="person__hand person__hand--left person--female__hand"></div>
</div>

I know how to set options for HtmlEditorConfig in _config.php, and this is part of what I currently have:

$tinyMCE->setOptions(array(
    'element_format' => 'html',
    'valid_elements' => '*
  • ', 'extended_valid_elements' => '*
  • ' ));

(FYI - that code above also isn't being formatted correctly. The values should be '* (open square bracket) * (close square bracket)').

I've tried setting various other options to `false`, but nothing makes any difference - `cleanup`, `apply_source_formatting`, `verify_html`

Nothing I try seems to make any difference, other than the `valid_elements` and `extended_valid_elements` settings above. I would be happy if TinyMCE left things alone completely and did no cleanup whatsoever - sometimes being 'helpful' can be too helpful...

I've also looked in the `sapphiremce_cleanup` method, but can't see anything there that might be causing this.

I also know I can use HTML entities instead of actual HTML, but then the code syntax highlighting doesn't work.