Freemarker compresses single_line without spaces

It seems that <@compress single_line = true> replaces line breaks with single spaces ("") instead of just suppressing them.

Example:

<@compress single_line=true>
"First cell"
<#if something >
    |"Second cell"
</#if>
|"Third cell"
</@compress>

Print:

"First cell" |"Second cell" |"Third cell"

It is not possible to analyze an outdated system just because of gaps between the pipes.

Is there a way to avoid this ?, perhaps a way to read every “nested” line in a macro to replace @compress functionality?

In the end, I do not need “structural source code”, but the view code, so assigning variables just to print the result will not be pleasant.

Thank you in advance, kindly.

+3
source share
3 answers

@compress , . @compress ( @ #). ... , , . TemplateDirectiveModel ( Writer ), , , myCompress. , #assign myCompress = 'com.example.MyCompressDirective'?new, #macro. <@myCompress>...</@myCompress>.

, . <#local captured><#nested></#local>, ?replace .. ... Java. ( , output_format HTML, XML .., - captured?markup_string?replace(...)?no_esc. , , .)

, , Writer Template.process.

+1

@ddekany, . , :

  • (^\s +)
  • (\ s + $)
  • (\n |\r)

( "rm" )

, , , 2 3;)

<#macro compress_single_line>
    <#local captured><#nested></#local>
${ captured?replace("^\\s+|\\s+$|\\n|\\r", "", "rm") }
</#macro>
<@compress_single_line>

    My free indented content    

        ${ someVar }

</@compress_single_line>

, @ddekany.

+6

The following solution also works fine:

<#assign var>
"First cell"
<#if something >
    |"Second cell"
</#if>
|"Third cell"
</#assign>
${var?replace("^\\s+|\\s+$|\\n|\\r", "", "rm")}
+1
source

All Articles