8
Whitespace Control
harttle edited this page 2019-08-06 00:51:59 +08:00

Like Shopify/liquid, liquidjs provides whitespace control via - markups and engine options.

via Markups

By default, all tags and output markups lines will generate a CR, and whitespace if there's an indentation. For example:

{%  author = "harttle" %}
{{ author }}

Outputs:


harttle

You can include hyphens in your tag syntax ({{-, -}}, {%-, -%}) to strip whitespace from left or right. For example:

{% assign author = "harttle" -%}
{{ author }}

Outputs:

harttle

In this case, the -%} strips the whitespace from the right side of the assign tag.

via Options

To enable whitespace control without spreading changes, use these options:

  • trimTagLeft
  • trimTagRight
  • trimValueRight
  • trimValueRight

liquidjs will NOT trim any whitespace by default, i.e. above options all default to false. For details of these options, see the README.

Greedy Mode

In greedy mode (enabled by the greedy option), all consecutive whitespace chars (including \n) will be trimmed.

Greedy mode is enabled by default to be compliant with shopify/liquid. And here is the test