Updated Whitespace Control (markdown)

Jun Yang
2017-10-30 00:49:20 +08:00
parent f3f92bdb1d
commit 6057fc9e6a
+20 -11
@@ -1,5 +1,4 @@
Like other variants of Liquid, liquidjs supports whitespace control markups. Like Shopify/liquid, liquidjs provides whitespace control via `-` markups and engine options.
In addition, you can change the default behaviors during construction.
## via Markups ## via Markups
@@ -10,6 +9,7 @@ For example:
```liquid ```liquid
{% assign author = "harttle" %} {% assign author = "harttle" %}
{{ author }} {{ author }}
``` ```
Outputs: Outputs:
@@ -17,14 +17,15 @@ Outputs:
``` ```
harttle harttle
``` ```
You can include hyphens in your tag syntax (`{{-`, `-}}`, `{%-`, `-%}`) to You can include hyphens in your tag syntax (`{{-`, `-}}`, `{%-`, `-%}`) to
strip whitespace from left or right. For example: strip whitespace from left or right. For example:
```liquid ```liquid
{% assign author = "harttle" -%} {%- assign author = "harttle" -%}
{{ author }} {{- author -}}
``` ```
Outputs: Outputs:
@@ -37,14 +38,22 @@ harttle
## via Options ## via Options
[liquidjs][liquidjs] will **NOT** trim any whitespace by default. To enable whitespace control without spreading changes, use these options:
By specifying `options.trim_left` or `options.trim_right`,
you can change this default behavior.
Note that the `trim_right` and `trim_left` only change the behavior of `{{ }}` and `{% %}`, * `trim_tag_left`
which means `{{-` (or `{%-`) will always trim whitespace from the left, * `trim_tag_right`
and `-}}` (or `-%}`) will always trim whitespace from the right regardless of the `trim_left` and `trim_right` options. * `trim_value_right`
* `trim_value_right`
For details of these options, see: <https://github.com/harttle/liquidjs> [liquidjs][liquidjs] will **NOT** trim any whitespace by default, i.e. above options all default to `false`.
For details of these options, see the [README](https://github.com/harttle/liquidjs).
## Greedy Mode
In greedy mode (enabled by the [greedy option][liquidjs]),
all consecutive whitespace chars (including `\n`) will be trimmed.
Greedy mode is enabled by default to be compliant with [shopify/liquid][shopify/liquid].
(If I'm wrong here, please file an issue)
[shopify/liquid]: https://github.com/Shopify/liquid
[liquidjs]: https://github.com/harttle/liquidjs [liquidjs]: https://github.com/harttle/liquidjs