Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add whitespace trimming functionality for notes and expressions #1122

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

jasmith-hs
Copy link
Contributor

In Jinja, tags, expressions, and notes should all support whitespace trimming:

You can also strip whitespace in templates by hand. If you add a minus sign (-) to the start or end of a block (e.g. a For tag), a comment, or a variable expression, the whitespaces before or after that block will be removed:

Currently, only TagNodes have support for whitespace trimming.

This also handles the scenario from #599 natively without needing to merge text nodes so I'm removing the text node merging logic.

@boulter
Copy link
Contributor

boulter commented Oct 20, 2023

Does jinja support trimming whitespace from notes and expressions? I can't think of notes causing any problems, but could leading whitespace trimming lead to misinterpretation as a negative value?

@jasmith-hs
Copy link
Contributor Author

Does jinja support trimming whitespace from notes and expressions?

Yes

I can't think of notes causing any problems, but could leading whitespace trimming lead to misinterpretation as a negative value?

No. There is a legacy issue where {{ -10 }} was treated as just 10, that was fixed with #903.
With the legacy override, the - is only looked for directly after the {{
Without the legacy override, the - is looked for as the first non-whitespace character after {{.

If you don't use the legacy override, then the whitespace trimming just won't work, but it wouldn't cause any change in the interpreted value

@jasmith-hs jasmith-hs merged commit 7a60dca into master Oct 27, 2023
4 checks passed
@jasmith-hs jasmith-hs deleted the note-trim branch October 27, 2023 18:28
@jasmith-hs jasmith-hs mentioned this pull request Oct 30, 2023
jasmith-hs added a commit that referenced this pull request Oct 31, 2023
This reverts commit 7a60dca, reversing
changes made to 23695ab.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants