Reputation: 1590
Ok, so I have been looking into this for a while now but from I can gather there is currently no option in TinyMCE to disable certain characters from being converted to entities.
I can understand the reason behind this, valid HTML is always nice, however, I really need a way to stop this, I have an email template editor where the client can edit there email templates and insert certain template variables (i.e. Account::first()->first_name which grabs the first name of the customer).
TinyMCE is converting ->
to ->
Is there anyway I can prevent this on the TinyMCE side of things?
Upvotes: 2
Views: 1303
Reputation: 198476
As I said extensively in comments - it makes no sense to stop TinyMCE producing valid HTML, because the results become unpredictable.
Instead, de-HTML-ify the template tags and only them to produce the correct template:
function sanitizeTemplate(content) {
var div = document.createElement('div');
return content.replace(/{{.*?}}/g, function(mustache) {
div.innerHTML = mustache;
return div.textContent;
});
}
// var content = tinyMCE.activeEditor.getContent();
content = "<p>Dear {{ Account::first()->first_name }}</p><p>Thank you for not using <script> tags.</p>";
snippet.log("Received from editor:");
snippet.log(content);
var template = sanitizeTemplate(content);
snippet.log("The fixed template:");
snippet.log(template);
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
Note that here everything that is not a template tag still remains intact, and valid HTML (in particular, the <script>
that the user typed will not magically become a HTML tag and try to get executed).
Upvotes: 1