]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Enable whitespace control within closing blocks
authorKevin Brown <kevin@kevin-brown.com>
Fri, 8 May 2020 23:55:24 +0000 (19:55 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 01:50:06 +0000 (21:50 -0400)
This enables the ability to force whitespace to be stripped following
the end of a block statement by adding a `-` before the closing
tag. This is supported both for stripped the space at the beginning
of a block as well as stripping the space that follows a block.

tatsu_grammar.txt
test_template.jinja

index b93c7e29e60327bf960fae7da55571a9b9ca83a8..2774e6d40076de8457ba73a9ce84892d305aab59 100644 (file)
@@ -29,12 +29,12 @@ raw_block_expression
 \r
 raw_block_start\r
     =\r
-    block_open "raw" block_close\r
+    block_open "raw" {SP}* block_close\r
     ;\r
 \r
 raw_block_end\r
     =\r
-    block_open "endraw" block_close\r
+    block_open "endraw" {SP}* block_close\r
     ;\r
 \r
 block_expression\r
@@ -50,16 +50,18 @@ block_start
 \r
 block_end\r
     =\r
-    block_open "end" name:IDENTIFIER block_close\r
+    block_open "end" name:IDENTIFIER {SP}* block_close\r
     ;\r
 \r
 block_open\r
     =\r
     @:"{%" {SP}*\r
     ;\r
+\r
 block_close\r
     =\r
-    {SP}* @:"%}"\r
+    | @:"%}"\r
+    | ( @:"-%}" {SP}* )\r
     ;\r
 \r
 line_block_expression\r
index c17c86c6d8ab2d5f6d8609f020d6dba0b1bd12bc..e77c6081136679d0a8dec872fe85e128e7bf2c88 100644 (file)
@@ -31,10 +31,10 @@ across lines #}
         The value will increase even more!\r
     {% endif %}\r
 {% endfor %}\r
-{% macro textarea(name, value='', rows=10, cols=40) %}\r
+{% macro textarea(name, value='', rows=10, cols=40) -%}\r
     <textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols\r
         }}">{{ value|e }}</textarea>\r
-{% endmacro %}\r
+{% endmacro -%}\r
 {# comment contents\r
 across lines #}\r
 <ul>\r