misc: keep django comments intact in skeleton pages (#25706)

This commit is contained in:
Frédéric Péters 2019-03-06 20:15:19 +01:00
parent d8068a046a
commit 8e262de57a
3 changed files with 7 additions and 2 deletions

View File

@ -40,7 +40,7 @@
{% trans "Footer" as name %}
{% placeholder "footer" name=name acquired=True %}
{% skeleton_extra_placeholder footer %}
<span style="display: none">{% now "Y-m-d H:i:s" %}</span>
<span style="display: none">{% now "Y-m-d H:i:s" %}</span> {# generation time #}
{% end_skeleton_extra_placeholder %}
{% endblock %}
</div>

View File

@ -25,7 +25,7 @@ from django.conf import settings
from django.core import signing
from django.core.exceptions import PermissionDenied
from django.template import VariableDoesNotExist
from django.template.base import TOKEN_BLOCK, TOKEN_VAR
from django.template.base import TOKEN_BLOCK, TOKEN_VAR, TOKEN_COMMENT
from django.template.defaultfilters import stringfilter
from django.utils import dateparse
@ -123,11 +123,15 @@ def skeleton_extra_placeholder(parser, token):
text.append('{{')
elif token.token_type == TOKEN_BLOCK:
text.append('{%')
elif token.token_type == TOKEN_COMMENT:
text.append('{# ')
text.append(token.contents)
if token.token_type == TOKEN_VAR:
text.append('}}')
elif token.token_type == TOKEN_BLOCK:
text.append('%}')
elif token.token_type == TOKEN_COMMENT:
text.append(' #}')
nodelist = parser.parse(('end_skeleton_extra_placeholder',))
parser.delete_first_token()

View File

@ -257,6 +257,7 @@ def test_page_skeleton(app):
# check {% now %} inside a skeleton_extra_placeholder is not interpreted
assert '{%now' in resp.text
assert '{# generation time #}' in resp.text
# check cells in footer are present even if there's no redirection page
page.slug = 'index'