]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
{% raw %} tests and note for documentation 851/head
authorngr <grischenko.n@gmail.com>
Mon, 14 May 2018 14:53:36 +0000 (10:53 -0400)
committerngr <grischenko.n@gmail.com>
Mon, 14 May 2018 14:53:36 +0000 (10:53 -0400)
docs/templates.rst
tests/test_lexnparse.py

index c60234b339774627f08c4b256fa67785a7575f45..6b123a215a38ec9ff0a6698f6fe33ef8628339ac 100644 (file)
@@ -271,6 +271,11 @@ include example Jinja syntax in a template, you can use this snippet::
         </ul>
     {% 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:
 
index 7da72c0bfe92ffa201e7aa4bb738b418481664e2..28a6076515f9ccb734bcf0e32165a73ae6b96682 100644 (file)
@@ -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