Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE escapes FreeMarker tags

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: '*[*]',
    
like image 229
naXa Avatar asked Oct 13 '16 15:10

naXa


People also ask

How to remove HTML tags from TinyMCE?

In the TinyMCE Editor I hit the HTML icon, and edit it from there. Once I click "ok" it goes away. So there's no need to save it to see the html tags gone . More sharing options...

What version of FreeMarker do I need to enable automatic escaping?

The kind of automatic escaping described here requires at least FreeMarker 2.3.24. If you have to use an earlier version, use the deprecated escape directive instead. Each template has an associated output format (a freemarker.core.OutputFormat instance) .

Does FreeMarker support ftlh and ftlx templates?

Furthermore it's recommended that FreeMarker is configured so that templates with ftlh and ftlx file extensions are automatically associated with the HTML and XML output formats, respectively. The predefined output formats are: Default implementation ( freemarker.core.*) Doesn't escape.

What is the recommended output format for FreeMarker templates?

Furthermore it's recommended that FreeMarker is configured so that templates with ftlh and ftlx file extensions are automatically associated with the HTML and XML output formats, respectively. The predefined output formats are:


1 Answers

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.

like image 77
ddekany Avatar answered Oct 03 '22 22:10

ddekany