Friday, January 26, 2018, 4:37:57 PM, Riehemann, Michael wrote:

> Hi Freemarker Devs,
>
> I'm not sure if this is a bug or feature request about the compress directive.
>
> Example:
>
> <#compress>
> <!DOCTYPE html>
> <html>
> <pre>   
>     #maybe a code example
>     With 4 whitespaces in every line
> </pre>
> </html>
> </#compress>
>
> Problem:
> The whitespace in the <pre> Tag is removed and will change the
> layout of it. Same for <code>. This is bad for code examples and
> breaks the concept of <pre> and <code>. Since we always use
> <#compress> in our outer template, you never have a change to avoid it.
>
> Ideas:
> 1. Fix it as a bug and skip <pre> and <code> in compress.
> 2. Add a new feature like <#nocompress/>
>
> What do you think?

FreeMarker doesn't try to interpret the static content. It doesn't
know what HTML is. It's just not that kind of template engine. So that
leaves us with idea 2. But, I think a 3rd one would be the best. As
#compress is just Writer filter basically (it doesn't remove
whitespace during the parsing phase), you just need a more
intelligent, HTML-aware FilterWriter. Especially as you do this for all
templates, can't you just pass a such Writer to Template.process? Then
the templates aren't polluted with that boilerplate. (If some templates
doesn't need it, something like <#ftl attributes = { 'compress': false }>
could be used.)

> -Michael Riehemann

-- 
Thanks,
 Daniel Dekany

Reply via email to