From 047dc82d67619c10db8fa90fad56f8c14c72782b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 7 Apr 2022 18:49:01 +0200 Subject: Add documentation for suppress_whitespace --- book/src/configuration.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'book/src') diff --git a/book/src/configuration.md b/book/src/configuration.md index 7c68724..05c18a0 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -11,8 +11,35 @@ 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. +suppress_whitespace = false ``` +In the default configuration, you can use the `-` operator to indicate that +whitespace should be suppressed before or after a block. For example: + +```jinja +
+ + +{%- if something %} +Hello +(% endif %} +``` + +In the template above, only the whitespace between `
` and `{%-` will be +suppressed. If you enable `suppress_whitespace`, whitespace characters before +and after each block will be suppressed by default. To preserve the whitespace +characters, you can use the `+` operator: + +```jinja +{% if something +%} +Hello +(%+ endif %} +``` + +In this example, `Hello` will be surrounded with newline characters. + Here is an example that defines two custom syntaxes: ```toml @@ -64,4 +91,4 @@ first escaper configured and ending with the default escapers for HTML (extensions `html`, `htm`, `xml`, `j2`, `jinja`, `jinja2`) and plain text (no escaping; `md`, `yml`, `none`, `txt`, and the empty string). Note that this means you can also define other escapers that match different extensions -to the same escaper. \ No newline at end of file +to the same escaper. -- cgit