Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 1.19 KB

whitespace-removal.md

File metadata and controls

51 lines (32 loc) · 1.19 KB

Sempare Template Engine

Copyright (c) 2019-2024 Sempare Limited

Whitespace Removal

Removing whitespace is a tricky problem in templates. In the template engine, attempts have been made to address this in a number of ways.

There are statements such as ignorenl and ignorews which allow for new lines and whitespaces to be stripped respectively.

Further, on the context, there are various options: eoStripRecurringNewlines, eoTrimLines, eoStripRecurringSpaces and eoConvertTabsToSpaces.

Below are some other ways in which hints can be provided to help trip whitespace and newlines.

Using script tag hints

Scripts start with <% and close with %>. These tags may have additional hints to assist with the removal of whitespace.

Using -

hello    <%- 'world' %>    <NL>
<NL>

This yields:

helloworld
<NL>

whitespace is removed before the '<%-', whitespace and a single newline is removed after the '%>'

block statements

This works with block statements as well

e.g.

    <%- if cond %>    <NL>
    <% 'hello' %><NL>
    <% end %><NL>

This results in:

    hello<NL>