Skip to content

Allow +%} to ignore trim_blocks#1240

Merged
davidism merged 1 commit intopallets:masterfrom
MLH-Fellowship:ignore-trim-blocks
Jun 22, 2020
Merged

Allow +%} to ignore trim_blocks#1240
davidism merged 1 commit intopallets:masterfrom
MLH-Fellowship:ignore-trim-blocks

Conversation

@amy-lei
Copy link
Copy Markdown
Contributor

@amy-lei amy-lei commented Jun 17, 2020

Resolves #1036

Summary:

  • When trim_block is enabled and a block ends with +%} or +#}, the behavior will be ignored.
    • Note: does not apply to raw start tags (i.e. {% raw +%} will raise an error) because they don't process the inner text
    • +%} is still allowed when trim_block is disabled but exhibits NOP behavior
    • So following the example from the original issue, when trim_block is enabled:
{% if something %}X{% endif +%}
more things

results in

X
more things

Tests:

  • Added tests to test_lexnparse.py
    • Specifically added a class for testing trim called TestTrimBlocks
    • Tests majority of the same cases as TrimLstripBlocks

Files affected:

  • lexer.py
  • test_lexnparse.py

Comment thread src/jinja2/lexer.py Outdated
@davidism davidism added this to the 3.0.0 milestone Jun 22, 2020
@davidism davidism force-pushed the ignore-trim-blocks branch from fd9beec to 6b01227 Compare June 22, 2020 17:22
@davidism davidism merged commit 03c719f into pallets:master Jun 22, 2020
@davidism davidism deleted the ignore-trim-blocks branch June 22, 2020 17:34
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow +%} to ignore trim_blocks like {%+ do for lstrip_blocks

3 participants