|
48 | 48 | pnamePat = re.compile(r'pname:(?P<param>\{?\w+\}?)') |
49 | 49 | codePat = re.compile(r'code:(?P<param>\w+)') |
50 | 50 |
|
| 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 | + |
51 | 59 | # Text that (may) not end sentences |
52 | 60 |
|
53 | 61 | # A single letter followed by a period, typically a middle initial. |
@@ -128,17 +136,18 @@ def __init__(self, |
128 | 136 | """Count of markup check warnings encountered.""" |
129 | 137 |
|
130 | 138 | 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. |
132 | 141 |
|
133 | 142 | Allows for contraction cases which will not end a line: |
134 | 143 |
|
135 | 144 | - A single letter (if breakInitial is True) |
136 | 145 | - Abbreviations: 'c.f.', 'e.g.', 'i.e.' (or mixed-case versions) |
137 | 146 | - 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))): |
142 | 151 | return False |
143 | 152 |
|
144 | 153 | return True |
|
0 commit comments