mirror of
https://github.com/django/django.git
synced 2025-08-09 03:19:20 +00:00
Fixed #14502 again -- saner verbatim closing token
Previously, the closing token for the verbatim tag was specified as the first argument of the opening token. As pointed out by Jannis, this is a rather major departure from the core tag standard. The new method reflects how you can give a specific closing name to {% block %} tags.
This commit is contained in:
parent
ffa6d95f65
commit
c57ba67331
@ -216,13 +216,8 @@ class Lexer(object):
|
|||||||
if token_string.startswith(VARIABLE_TAG_START):
|
if token_string.startswith(VARIABLE_TAG_START):
|
||||||
token = Token(TOKEN_VAR, token_string[2:-2].strip())
|
token = Token(TOKEN_VAR, token_string[2:-2].strip())
|
||||||
elif token_string.startswith(BLOCK_TAG_START):
|
elif token_string.startswith(BLOCK_TAG_START):
|
||||||
if block_content.startswith('verbatim'):
|
if block_content[:9] in ('verbatim', 'verbatim '):
|
||||||
bits = block_content.split(' ', 1)
|
self.verbatim = 'end%s' % block_content
|
||||||
if bits[0] == 'verbatim':
|
|
||||||
if len(bits) > 1:
|
|
||||||
self.verbatim = bits[1]
|
|
||||||
else:
|
|
||||||
self.verbatim = 'endverbatim'
|
|
||||||
token = Token(TOKEN_BLOCK, block_content)
|
token = Token(TOKEN_BLOCK, block_content)
|
||||||
elif token_string.startswith(COMMENT_TAG_START):
|
elif token_string.startswith(COMMENT_TAG_START):
|
||||||
content = ''
|
content = ''
|
||||||
|
@ -1291,18 +1291,14 @@ def verbatim(parser, token):
|
|||||||
{% don't process this %}
|
{% don't process this %}
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
|
|
||||||
You can also specify an alternate closing tag::
|
You can also designate a specific closing tag block (allowing the
|
||||||
|
unrendered use of ``{% endverbatim %}``)::
|
||||||
|
|
||||||
{% verbatim -- %}
|
{% verbatim myblock %}
|
||||||
...
|
...
|
||||||
{% -- %}
|
{% endverbatim myblock %}
|
||||||
"""
|
"""
|
||||||
bits = token.contents.split(' ', 1)
|
nodelist = parser.parse(('endverbatim',))
|
||||||
if len(bits) > 1:
|
|
||||||
closing_tag = bits[1]
|
|
||||||
else:
|
|
||||||
closing_tag = 'endverbatim'
|
|
||||||
nodelist = parser.parse((closing_tag,))
|
|
||||||
parser.delete_first_token()
|
parser.delete_first_token()
|
||||||
return VerbatimNode(nodelist.render(Context()))
|
return VerbatimNode(nodelist.render(Context()))
|
||||||
|
|
||||||
|
@ -1047,12 +1047,12 @@ Django's syntax. For example::
|
|||||||
{{if dying}}Still alive.{{/if}}
|
{{if dying}}Still alive.{{/if}}
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
|
|
||||||
You can also specify an alternate closing tag::
|
You can also designate a specific closing tag, allowing the use of
|
||||||
|
``{% endverbatim %}`` as part of the unrendered contents::
|
||||||
|
|
||||||
{% verbatim finished %}
|
{% verbatim myblock %}
|
||||||
The verbatim tag looks like this:
|
Avoid template rendering via the {% verbatim %}{% endverbatim %} block.
|
||||||
{% verbatim %}{% endverbatim %}
|
{% endverbatim myblock %}
|
||||||
{% finished %}
|
|
||||||
|
|
||||||
.. templatetag:: widthratio
|
.. templatetag:: widthratio
|
||||||
|
|
||||||
|
@ -1623,7 +1623,7 @@ class Templates(unittest.TestCase):
|
|||||||
'verbatim-tag03': ("{% verbatim %}It's the {% verbatim %} tag{% endverbatim %}", {}, "It's the {% verbatim %} tag"),
|
'verbatim-tag03': ("{% verbatim %}It's the {% verbatim %} tag{% endverbatim %}", {}, "It's the {% verbatim %} tag"),
|
||||||
'verbatim-tag04': ('{% verbatim %}{% verbatim %}{% endverbatim %}{% endverbatim %}', {}, template.TemplateSyntaxError),
|
'verbatim-tag04': ('{% verbatim %}{% verbatim %}{% endverbatim %}{% endverbatim %}', {}, template.TemplateSyntaxError),
|
||||||
'verbatim-tag05': ('{% verbatim %}{% endverbatim %}{% verbatim %}{% endverbatim %}', {}, ''),
|
'verbatim-tag05': ('{% verbatim %}{% endverbatim %}{% verbatim %}{% endverbatim %}', {}, ''),
|
||||||
'verbatim-tag06': ("{% verbatim -- %}Don't {% endverbatim %} just yet{% -- %}", {}, "Don't {% endverbatim %} just yet"),
|
'verbatim-tag06': ("{% verbatim special %}Don't {% endverbatim %} just yet{% endverbatim special %}", {}, "Don't {% endverbatim %} just yet"),
|
||||||
}
|
}
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user