Skip to content

Commit 3c8c221

Browse files
committed
Reflow breaks sentence on ? and !
Update the reflow script to break a line on a sentence that ends with a question mark or exclamation point.
1 parent 2486dd6 commit 3c8c221

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

adoc/scripts/reflow.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
pnamePat = re.compile(r'pname:(?P<param>\{?\w+\}?)')
4949
codePat = re.compile(r'code:(?P<param>\w+)')
5050

51+
# Word that ends a sentence.
52+
# (A word that ends with a period, question mark, or exclamation point;
53+
# possible inside a trailing parenthesis like "foo.)"
54+
# However, a punctuation mark with no preceding character does not end a
55+
# sentence. This happens, for example, when a C++ expression appears in a
56+
# sentence like "cond ? a : b".
57+
endSentencePunct = re.compile(r'.([.?!]|[.?!]\))$')
58+
5159
# Text that (may) not end sentences
5260

5361
# A single letter followed by a period, typically a middle initial.
@@ -128,17 +136,18 @@ def __init__(self,
128136
"""Count of markup check warnings encountered."""
129137

130138
def endSentence(self, word, nextWord):
131-
"""Return True if word ends with a sentence-period, False otherwise.
139+
"""Return True if word ends with a sentence-ending punctuation
140+
character, False otherwise.
132141
133142
Allows for contraction cases which will not end a line:
134143
135144
- A single letter (if breakInitial is True)
136145
- Abbreviations: 'c.f.', 'e.g.', 'i.e.' (or mixed-case versions)
137146
- The word "etc." when it is followed by a lower case word"""
138-
if ((word[-1:] != '.' and word[-2:] != '.)') or
139-
endAbbrev.search(word) or
140-
word == "etc." and startsLowerCase.match(nextWord) or
141-
(self.breakInitial and endInitial.match(word))):
147+
if (not endSentencePunct.search(word) or
148+
endAbbrev.search(word) or
149+
(word == "etc." and startsLowerCase.match(nextWord)) or
150+
(self.breakInitial and endInitial.match(word))):
142151
return False
143152

144153
return True

0 commit comments

Comments
 (0)