Skip to content

Commit 24ede9a

Browse files
committed
In wordwrap(), consider lines consisting entirely of some non-alphanumeric characters like ---- or === to be block (paragraph) separators. Fixes issue ietf-tools#2806.
- Legacy-Id: 16790
1 parent 12bf466 commit 24ede9a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ietf/utils/text.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def wordwrap(text, width=80):
6262
of short lines"""
6363
if not isinstance(text, six.string_types):
6464
return text
65+
def block_separator(s):
66+
"Look for lines of identical symbols, at least three long"
67+
ss = s.strip()
68+
chars = set(ss)
69+
return len(chars) == 1 and len(ss) >= 3 and ss[0] in set('#*+-.=_~')
6570
width = int(width) # ensure we have an int, if this is used as a template filter
6671
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
6772
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
@@ -74,7 +79,7 @@ def wordwrap(text, width=80):
7479
line = line.expandtabs().rstrip()
7580
indent = " " * (len(line) - len(line.lstrip()))
7681
ind = len(indent)
77-
if wrapped and line.strip() != "" and indent == prev_indent:
82+
if wrapped and line.strip() != "" and indent == prev_indent and not block_separator(line):
7883
line = filled[-1] + " " + line.lstrip()
7984
filled = filled[:-1]
8085
else:

0 commit comments

Comments
 (0)