Whitespace Control

Jun Yang edited this page Oct 29, 2017 · 7 revisions

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 }}



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

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



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:

  • trim_tag_left
  • trim_tag_right
  • trim_value_right
  • trim_value_right

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

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.