Introduce a word-wrapping filter that checks if there are lines (containing spaces to not
count URLs) longer than 100 characters, and only wraps the text if that's the case, to prevent messing up pre-wrapped text. Use this filter in the review email code. Branch ready for merge. - Legacy-Id: 13495
This commit is contained in:
parent
be28c2b2db
commit
1a59cf60d3
|
@ -17,6 +17,7 @@ from django.utils.html import escape
|
|||
from django.template.defaultfilters import truncatewords_html, linebreaksbr, stringfilter, striptags, urlize
|
||||
from django.utils.safestring import mark_safe, SafeData
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.text import wrap
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
@ -313,6 +314,19 @@ def wrap_text(text, width=72):
|
|||
prev_indent = indent
|
||||
return "\n".join(filled)
|
||||
|
||||
@register.filter
|
||||
def wrap_text_if_unwrapped(text, width=72, max_tolerated_line_length=100):
|
||||
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
|
||||
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
|
||||
|
||||
contains_long_lines = any(" " in l and len(l) > max_tolerated_line_length
|
||||
for l in text.split("\n"))
|
||||
|
||||
if contains_long_lines:
|
||||
return wrap(text, width)
|
||||
else:
|
||||
return text
|
||||
|
||||
@register.filter(name="compress_empty_lines")
|
||||
def compress_empty_lines(text):
|
||||
text = re.sub("( *\n){3,}", "\n\n", text)
|
||||
|
|
|
@ -660,7 +660,7 @@ class ReviewTests(TestCase):
|
|||
"state": ReviewRequestStateName.objects.get(slug="part-completed").pk,
|
||||
"reviewed_rev": review_req.doc.rev,
|
||||
"review_submission": "enter",
|
||||
"review_content": "This is a review\nwith two lines",
|
||||
"review_content": "This is a review with a somewhat long line spanning over 80 characters to test word wrapping\nand another line",
|
||||
})
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
|
@ -694,7 +694,7 @@ class ReviewTests(TestCase):
|
|||
"state": ReviewRequestStateName.objects.get(slug="completed").pk,
|
||||
"reviewed_rev": review_req.doc.rev,
|
||||
"review_submission": "enter",
|
||||
"review_content": "This is another review\nwith\nthree lines",
|
||||
"review_content": "This is another review with a really, really, really, really, really, really, really, really, really, really long line",
|
||||
})
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% autoescape off %}{% filter wordwrap:70 %}{% if review_req.state_id == "part-completed" %}Review is partially done. Another review request has been registered for completing it.
|
||||
{% autoescape off %}{% load ietf_filters %}{% filter wrap_text_if_unwrapped:80 %}{% if review_req.state_id == "part-completed" %}Review is partially done. Another review request has been registered for completing it.
|
||||
|
||||
{% endif %}Reviewer: {{ review_req.reviewer.person }}
|
||||
Review result: {{ review_req.result.name }}
|
||||
|
|
Loading…
Reference in a new issue