[
https://issues.apache.org/jira/browse/FREEMARKER-123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16978706#comment-16978706
]
Dániel Dékány edited comment on FREEMARKER-123 at 11/20/19 7:58 PM:
--------------------------------------------------------------------
So that's one of those cases where white-space matters in HTML unfortunately
(blank line before DOCTYPE), although I'm not sure which browsers are still
particular about that. Controlling white-space precisely is difficult in most
(all?) template languages. So maybe the safest way is to do that trimming in
the {{Writer}} that's passed to {{Template.process}}. Perhaps FreeMarker should
include such a {{Writer}} though.
Also, I'm not sure what's in those {{#include}}-d templates. Generally,
{{#import}} and using macros defined inside them avoids leading blanks.
Or, if a template that will be {{#include}}-d doesn't output anything, only
sets variables and such, then it can be started with {{<#ftl
strip_text=true>}}. Beware, that will also remove non-white-space top level
text.
Last not least, good control over white-space is often desirable when
generating non-HTML non-XML text, but addressing that in more general cases
will mean runtime overhead, as removing white-space that people intuitively
think is just formatting is not possible statically in many cases. So that's a
feature that should be added, but is complex, and was not yet done.
was (Author: ddekany):
So that's one of those cases where white-space matters in HTML unfortunately
(blank line before DOCTYPE), although I'm not sure which browsers are still
particular about that. Controlling white-space precisely is difficult in most
(all?) template languages. So maybe the safest way is to do that trimming in
the {{Writer}} that's passed to {{Template.process}}. Perhaps FreeMarker should
include such a {{Writer}} though.
Also, I'm not sure what's in those {{#include}}-d templates. Generally,
{{#import}} and using macros defined inside them avoids leading blanks.
Or, if a template that will be {{#include}}-d doesn't output anything, only
sets variables and such, then it can be started with {{<#ftl
strip_text=true>}}. Beware, that will also remove non-white-space top level
text.
Last not least, good control over white-space is often desirable when
generating non-HTML non-XML text, but addressing that in more general cases
will mean runtime overhead, as removing white-space that people intuitively
think is just formatting is not possible statically, except in many cases.
> Trim output whitespace
> ----------------------
>
> Key: FREEMARKER-123
> URL: https://issues.apache.org/jira/browse/FREEMARKER-123
> Project: Apache Freemarker
> Issue Type: Improvement
> Reporter: Vojtech Knyttl
> Priority: Major
> Attachments: Screenshot 2019-11-20 at 14.00.56.png
>
>
> We use a lot of recursively included files, which might have a lot of
> indentation. The result is, that we sometimes get even 30 empty lines before
> `<html>`.
> !Screenshot 2019-11-20 at 14.00.56.png!
> It would be great to allow dropping all whitespace before first
> non-whitespace chars.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)