9
votes

I use TinyMCE 4 as a WYSIWYG editor for HTML pages. But when I use FreeMarker tag idioms like <#if condition>, <#else> in TinyMCE, they get mangled when I go from "code view" (simple textarea) to the "design view" (WYSIWYG).

For example if I write HTML in a simple textarea (Code view)

<#if x == 1>
  x is 1
<#else>
  x is not 1
</#if>

and then toggle to editor and back to Code view, it becomes:

&lt;#if x == 1&gt;
    x is 1
&lt;#else/&gt;
    x is not 1
&lt;/#if&gt;

As you can see FreeMarker tags are getting escaped in the toggling.

Q1: Is there a way to configure TinyMCE to handle these tags so that when I toggle back-and-forth between the editor and the Code view the markup remains consistent?
Q2: Or (saying the same thing in a different way) does TinyMCE have support for FreeMarker?


What have I tried so far?

  • I've used the alternative (square bracket) syntax.
    But I've encountered different problems since [#tag]...[/#tag] is treated as plain text by TinyMCE.
  • I've tried to disable HTML validation in configuration:

    verify_html: false,
    valid_elements: '*[*]',
    
1

1 Answers

1
votes

I think you will have to un-mangle them in a custom freemarker.cache.TemplateLoader implementation, which wraps your normal TemplateLoader. Though of course, there will be an ambiguity if the user indeed types "<#" or "</#", but I'm not sure if that's a problem in your application.