]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Parse raw blocks and comments
authorKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 15:28:26 +0000 (11:28 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 15:28:26 +0000 (11:28 -0400)
Comments get ignored by the parser and raw blocks just get output
directly as a string into the AST.

new_parser.py

index 3c74227a026f589258e9bd704e54ce846c192270..c8b6ec4aca78fc8d6a92daef3eea9b6fd6820f3a 100644 (file)
@@ -20,6 +20,12 @@ def parse(ast):
     if 'start' in ast and 'end' in ast:\r
         return parse_block_pair(ast)\r
 \r
+    if 'raw' in ast:\r
+        return parse_raw(ast)\r
+\r
+    if 'comment' in ast:\r
+        return parse_comment(ast)\r
+\r
     return None\r
 \r
 def parse_block(ast):\r
@@ -70,6 +76,9 @@ def parse_block_with(ast):
 \r
     return with_node\r
 \r
+def parse_comment(ast):\r
+    return None\r
+\r
 def parse_literal(ast):\r
     if 'literal_type' not in ast:\r
         raise\r
@@ -113,6 +122,11 @@ def parse_print(ast):
 \r
     return nodes.Output([node])\r
 \r
+def parse_raw(ast):\r
+    return parse_output(\r
+        ''.join(ast['raw'])\r
+    )\r
+\r
 def parse_template(ast):\r
     return nodes.Template(parse(ast), lineno=1)\r
 \r