This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
Enable Jinja2 whitespace control by default #44
+12
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch turns on Jinja2 whitespace control by default. This will greatly reduce the need to use manual whitespace control in the templates in order to produce good looking output.
Rationale:
Jinja2 on the web: The common use of Jinja2 is to serve web requests in realtime. The rendered templates are rarely inspected by a human and have a lifetime of a few minutes (at best). In this context, it is reasonable to turn off whitespace control to save some processing time and maximize throughput.
Jinja2 on j2cli: j2cli is meant mostly as a batch processing tool. I.e. it is invoked only periodically. The generated output persists for much longer, and it is quite likely to be inspected by a human. Therefore, enabling whitespace control by default to produce better looking output makes
sense.
Side-effects:
There are barely any side-effects from this patch. Where manual space control is used in templates (e.g.
{%- ... -%}
) the-
modifiers will become redundant. They can be eventually removed at a time of convenience.The only side-effect I've noticed is the case of consecutive
{% include ... %}
tags. In this case, whitespace control needs to be manually disabled using the+
modifier. E.g. this:becomes:
But I love whitespace in my output:
In case someone absolutely hates this behaviour, it can be turned off with the new
--no-compact
flag.