Output control - misonou/waterpipe GitHub Wiki

HTML mode

By default, reserved characters from evaluated outputs are encoded, while the static content in the template are parsed as valid HTML with whitespaces being collapsed. For example,

<p class="example">{{html}}</p>

will produce:

<p class="example">&lt;b&gt;This is HTML.&lt;/b&gt;</p>

Whitespaces

Broken and unmatched tags

Broken and unmatched tags are properly fixed:

<div a=\"\" b\" c=><b></div></b>

will produce:

<div a="" b c><b></b></div>

Unescaping content

Evaluation can be output as-is by prefixing the expression by and & character. For example,

<p class="example">{{&html}}</p>

will produce:

<p class="example"><b>This is HTML.</b></p>

Indentation

Verbatim mode

When template content has to be treated as-is without being parsed and HTML, set html options to false.

waterpipe(template, data, { html: false });

For example,

--------------------
< This is not HTML >
--------------------

{{html}}

--------------------

will produce:

--------------------
< This is not HTML >
--------------------

<b>This is HTML.</b>

--------------------

Line stripping

In verbatim mode, whitespaces and indentations are preserved except for the lines containing only flow-control tags. For example,

Items:

{{foreach items}}
  - {{.}}
{{/foreach}}

will produce:

Items:

  - 1
  - 2
  - 3

Noted that line 2 and 4 in the template are stripped.

⚠️ **GitHub.com Fallback** ⚠️