aboutsummaryrefslogtreecommitdiffstats
path: root/book
diff options
context:
space:
mode:
authorLibravatar Raimundo Saona <37874270+saona-raimundo@users.noreply.github.com>2023-04-01 17:24:29 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-04-03 11:43:26 +0200
commit4c98685b81509a59bf7719321eb2136d7dccca38 (patch)
treec3d8fec1d705b9557cb1b113dfe853112208a382 /book
parent25e1a51e95bfcecc7ecf16a175dd71820576eaf1 (diff)
downloadaskama-4c98685b81509a59bf7719321eb2136d7dccca38.tar.gz
askama-4c98685b81509a59bf7719321eb2136d7dccca38.tar.bz2
askama-4c98685b81509a59bf7719321eb2136d7dccca38.zip
Improve whitespace documentation
Diffstat (limited to 'book')
-rw-r--r--book/src/template_syntax.md29
1 files changed, 27 insertions, 2 deletions
diff --git a/book/src/template_syntax.md b/book/src/template_syntax.md
index 5e69bc9..c90820c 100644
--- a/book/src/template_syntax.md
+++ b/book/src/template_syntax.md
@@ -88,7 +88,7 @@ includes only whitespace, whitespace suppression on either side will
completely suppress that literal content.
If the whitespace default control is set to "suppress" and you want
-to keep whitespace characters on one side of a block or of an
+to preserve whitespace characters on one side of a block or of an
expression, you need to use `+`. Example:
```text
@@ -96,9 +96,34 @@ expression, you need to use `+`. Example:
class="something">text</a>
```
-In the above example, it allows to keep one whitespace character
+In the above example, one whitespace character is kept
between the `href` and the `class` attributes.
+There is a third possibility. In case you want to suppress all whitespace
+characters except one (`"minimize"`), 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.
+
+Whitespace controls can also be defined by a
+[configuration file](configuration.md) or in the derive macro.
+These definitions follow the global-to-local preference:
+1. Inline (`-`, `+`, `~`)
+2. Derive (`#[template(whitespace = "suppress")]`)
+3. Configuration (in `askama.toml`, `whitespace = "preserve"`)
+
+Two inline whitespace controls may point to the same whitespace span.
+In this case, they are resolved by the following preference.
+1. Suppress (`-`)
+2. Minimize (`~`)
+3. Preserve (`+`)
+
## Template inheritance
Template inheritance allows you to build a base template with common