misc: introduce a {% newline %} tag (#57622)

This commit is contained in:
Frédéric Péters 2021-10-05 18:26:10 +02:00
parent 1e7f76648a
commit 71b0291a4a
2 changed files with 11 additions and 0 deletions

View File

@ -1271,3 +1271,9 @@ def test_site_options_booleans(pub):
assert Template('{% if something_false == "false" %}hello{% endif %}').render(context) == 'hello'
assert Template('{% if something_false == True %}hello{% endif %}').render(context) == ''
assert Template('{% if something_false == "true" %}hello{% endif %}').render(context) == ''
def test_newline(pub):
context = pub.substitutions.get_context_variables()
assert Template('a{% newline %}b').render(context) == 'a\nb'
assert Template('a{% newline windows=True %}b').render(context) == 'a\r\nb'

View File

@ -853,3 +853,8 @@ def qrcode_filter(value, name=None):
upload = upload_storage.PicklableUpload(name or 'qrcode.png', 'image/png')
upload.receive([buf.getvalue()])
return upload
@register.simple_tag
def newline(windows=False):
return '\r\n' if windows else '\n'