From 79747c3f8f6dc472ea37aac4d3d6b134c8269009 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 7 Apr 2022 18:49:01 +0200 Subject: [PATCH] Add documentation for automatic_block_trim --- book/src/configuration.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 7c687241c..220b43a0b 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -11,8 +11,37 @@ 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. +automatic_trim_block = false ``` +About `automatic_trim_block`, if you want to trim whitespace before or after a +block, you need to use the minus sign. For example: + +```jinja +
+ + +{%- if something %} +Hello +(% endif %} +``` + +In this case, only the content between `
` and `{%-` will be trimmed. If +this option is enabled, all content before and after each jinja block will be +trimmed. + +If the option is enabled but you don't want a part to be trimmed, use the plus +(`+`) sign: + +```jinja +{% if something +%} +Hello +(%+ endif %} +``` + +In this example, `Hello` will be surrounded with backlines. + Here is an example that defines two custom syntaxes: ```toml @@ -64,4 +93,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.