Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template keyword to output block unchanged #318

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion tornado/template.py
Expand Up @@ -533,6 +533,17 @@ def _format_code(code):


def _parse(reader, template, in_block=None):
# Skip everything if we're in a verbatim block
if in_block == "verbatim":
block_end = reader.find("{% end %}")
if block_end == -1 or block_end + 1 == reader.remaining():
raise ParseError("Missing {%% end %%} block for verbatim")
unparsed_text = reader.consume(block_end)
# Consume the end block
# NOTE: the magic number 9 comes from: len('{% end %}') == 9
reader.consume(9)
return unparsed_text

body = _ChunkList([])
while True:
# Find next template directive
Expand Down Expand Up @@ -658,7 +669,7 @@ def _parse(reader, template, in_block=None):
body.chunks.append(block)
continue

elif operator in ("apply", "block", "try", "if", "for", "while"):
elif operator in ("apply", "block", "try", "if", "for", "while", "verbatim"):
# parse inner body recursively
block_body = _parse(reader, template, operator)
if operator == "apply":
Expand All @@ -669,6 +680,8 @@ def _parse(reader, template, in_block=None):
if not suffix:
raise ParseError("block missing name on line %d" % line)
block = _NamedBlock(suffix, block_body, template)
elif operator == "verbatim":
block = _Text(block_body)
else:
block = _ControlBlock(contents, block_body)
body.chunks.append(block)
Expand Down