From: ngr Date: Mon, 14 May 2018 14:53:36 +0000 (-0400) Subject: {% raw %} tests and note for documentation X-Git-Tag: 2.11.0~118^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F851%2Fhead;p=thirdparty%2Fjinja.git {% raw %} tests and note for documentation --- diff --git a/docs/templates.rst b/docs/templates.rst index c60234b3..6b123a21 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -271,6 +271,11 @@ include example Jinja syntax in a template, you can use this snippet:: {% endraw %} +.. admonition:: Note + + Minus sign at the end of ``{% raw -%}`` tag cleans all the spaces and newlines + preceding the first character of your raw data. + .. _line-statements: diff --git a/tests/test_lexnparse.py b/tests/test_lexnparse.py index 7da72c0b..28a60765 100644 --- a/tests/test_lexnparse.py +++ b/tests/test_lexnparse.py @@ -67,6 +67,18 @@ class TestLexer(object): tmpl = env.from_string('1 {%- raw -%} 2 {%- endraw -%} 3') assert tmpl.render() == '123' + def test_raw3(self, env): + # The second newline after baz exists because it is AFTER the {% raw %} and is ignored. + env = Environment(lstrip_blocks=True, trim_blocks=True) + tmpl = env.from_string("bar\n{% raw %}\n {{baz}}2 spaces\n{% endraw %}\nfoo") + assert tmpl.render(baz='test') == "bar\n\n {{baz}}2 spaces\nfoo" + + def test_raw4(self, env): + # The trailing dash of the {% raw -%} cleans both the spaces and newlines up to the first character of data. + env = Environment(lstrip_blocks=True, trim_blocks=False) + tmpl = env.from_string("bar\n{%- raw -%}\n\n \n 2 spaces\n space{%- endraw -%}\nfoo") + assert tmpl.render() == "bar2 spaces\n spacefoo" + def test_balancing(self, env): env = Environment('{%', '%}', '${', '}') tmpl = env.from_string('''{% for item in seq