Skip to content

Commit 1a59cf6

Browse files
committed
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
1 parent be28c2b commit 1a59cf6

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

ietf/doc/templatetags/ietf_filters.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from django.template.defaultfilters import truncatewords_html, linebreaksbr, stringfilter, striptags, urlize
1818
from django.utils.safestring import mark_safe, SafeData
1919
from django.utils.html import strip_tags
20+
from django.utils.text import wrap
2021

2122
register = template.Library()
2223

@@ -313,6 +314,19 @@ def wrap_text(text, width=72):
313314
prev_indent = indent
314315
return "\n".join(filled)
315316

317+
@register.filter
318+
def wrap_text_if_unwrapped(text, width=72, max_tolerated_line_length=100):
319+
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
320+
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
321+
322+
contains_long_lines = any(" " in l and len(l) > max_tolerated_line_length
323+
for l in text.split("\n"))
324+
325+
if contains_long_lines:
326+
return wrap(text, width)
327+
else:
328+
return text
329+
316330
@register.filter(name="compress_empty_lines")
317331
def compress_empty_lines(text):
318332
text = re.sub("( *\n){3,}", "\n\n", text)

ietf/doc/tests_review.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def test_partially_complete_review(self):
660660
"state": ReviewRequestStateName.objects.get(slug="part-completed").pk,
661661
"reviewed_rev": review_req.doc.rev,
662662
"review_submission": "enter",
663-
"review_content": "This is a review\nwith two lines",
663+
"review_content": "This is a review with a somewhat long line spanning over 80 characters to test word wrapping\nand another line",
664664
})
665665
self.assertEqual(r.status_code, 302)
666666

@@ -694,7 +694,7 @@ def test_partially_complete_review(self):
694694
"state": ReviewRequestStateName.objects.get(slug="completed").pk,
695695
"reviewed_rev": review_req.doc.rev,
696696
"review_submission": "enter",
697-
"review_content": "This is another review\nwith\nthree lines",
697+
"review_content": "This is another review with a really, really, really, really, really, really, really, really, really, really long line",
698698
})
699699
self.assertEqual(r.status_code, 302)
700700

ietf/templates/review/completed_review.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% 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.
1+
{% 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.
22

33
{% endif %}Reviewer: {{ review_req.reviewer.person }}
44
Review result: {{ review_req.result.name }}

0 commit comments

Comments
 (0)