Arguments in favour of the Structured Whitespace Handling
The typical use scenario for velocity is to add VTL markup to text pages. Two forms can be differentiated:
- a velocity directive on a line by itself
- directives embedded within other text.
In the first case, it is desireable to allow indenting of the markup to better visualize the constructs; OTOH, the rendered output should not contain the whitespace indentation at the line beginning and the linefeed at the end. Example:
For the second case, with embedded directives in a line, surrounding whitespaces should not be gobbled. A typical example of this from is:
This proposal does not deal/affect VTL-references.
Very rare cases exist where VTL-markup is embedded in non-line based files (binary?). For such uses, it is desireable to allow switching off the whitespace gobbling as a whole. A nice solution would be to add a pragma directive:
This should turn the gobbling off only within the declaring template. It should not affect any outer template parsing a template declaring the whitespace handling pragma.
The implementation of this proposal implies that the velocity parser must be aware of whitespaces before and after directives, and that during rendering these are handled according to the whitepace handling pragma switch.
Early filtering implementation
Here is an implementation that uses a java.io.FilterInputStream to filter unwanted whitespaces while loading the resource: StructuredGlobbingResourceLoader