From f997ba97bd298e219f3286fa792ec10874a34079 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 21 Apr 2022 16:50:56 +0200 Subject: Add documentation for `~` and `"minimize"` --- book/src/configuration.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'book/src') diff --git a/book/src/configuration.md b/book/src/configuration.md index acc9751..abf276d 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -11,7 +11,7 @@ This example file demonstrates the default configuration: [general] # Directories to search for templates, relative to the crate root. dirs = ["templates"] -# Unless you add a `-` in a block, whitespace won't be trimmed. +# Unless you add a `-` in a block, whitespace characters won't be trimmed. whitespace = "preserve" ``` @@ -24,7 +24,7 @@ whitespace should be suppressed before or after a block. For example: {%- if something %} Hello -(% endif %} +{% endif %} ``` In the template above, only the whitespace between `
` and `{%-` will be @@ -35,11 +35,26 @@ characters, you can use the `+` operator: ```jinja {% if something +%} Hello -(%+ endif %} +{%+ endif %} ``` In this example, `Hello` will be surrounded with newline characters. +There is a third possibility: in case you want to suppress all whitespace +characters except one, you can use `~`: + +```jinja +{% if something ~%} +Hello +{%~ endif %} +``` + +To be noted, if one of the trimmed characters is a newline, then the only +character remaining will be a newline. + +If you want this to be the default behaviour, you can set `whitespace` to +`"minimize"`. + Here is an example that defines two custom syntaxes: ```toml -- cgit