|
132 | 132 | r"^\s*\.\. (" + "|".join(DIRECTIVES_CONTAINING_RST) + ")::" |
133 | 133 | ) |
134 | 134 |
|
135 | | -ALL_DIRECTIVES = ( |
136 | | - "(" |
137 | | - + "|".join(DIRECTIVES_CONTAINING_RST + DIRECTIVES_CONTAINING_ARBITRARY_CONTENT) |
138 | | - + ")" |
139 | | -) |
140 | | - |
141 | 135 | QUOTE_PAIRS = [ |
142 | 136 | "»»", # Swedish |
143 | 137 | "‘‚", # Albanian/Greek/Turkish |
|
184 | 178 | UNICODE_ALLOWED_AFTER_INLINE_MARKUP = r"[\p{Pe}\p{Pi}\p{Pf}\p{Pd}\p{Po}]" |
185 | 179 |
|
186 | 180 |
|
| 181 | +def get_all_directives() -> str: |
| 182 | + return ( |
| 183 | + "(" |
| 184 | + + "|".join(DIRECTIVES_CONTAINING_RST + DIRECTIVES_CONTAINING_ARBITRARY_CONTENT) |
| 185 | + + ")" |
| 186 | + ) |
| 187 | + |
| 188 | + |
187 | 189 | def inline_markup_gen(start_string, end_string, extra_allowed_before=""): |
188 | 190 | """Generate a regex matching an inline markup. |
189 | 191 |
|
@@ -259,19 +261,24 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""): |
259 | 261 | rf"(^|\s)`:{SIMPLENAME}:{INTERPRETED_TEXT_RE.pattern}", flags=re.VERBOSE | re.DOTALL |
260 | 262 | ) |
261 | 263 |
|
| 264 | + |
262 | 265 | # Find comments that look like a directive, like: |
263 | 266 | # .. versionchanged 3.6 |
264 | 267 | # or |
265 | 268 | # .. versionchanged: 3.6 |
266 | 269 | # as it should be: |
267 | 270 | # .. versionchanged:: 3.6 |
268 | | -SEEMS_DIRECTIVE_RE = re.compile(rf"^\s*(?<!\.)\.\. {ALL_DIRECTIVES}([^a-z:]|:(?!:))") |
| 271 | +def seems_directive_re() -> re.Pattern[str]: |
| 272 | + return re.compile(rf"^\s*(?<!\.)\.\. {get_all_directives()}([^a-z:]|:(?!:))") |
| 273 | + |
269 | 274 |
|
270 | 275 | # Find directive prefixed with three dots instead of two, like: |
271 | 276 | # ... versionchanged:: 3.6 |
272 | 277 | # instead of: |
273 | 278 | # .. versionchanged:: 3.6 |
274 | | -THREE_DOT_DIRECTIVE_RE = re.compile(rf"\.\.\. {ALL_DIRECTIVES}::") |
| 279 | +def three_dot_directive_re() -> re.Pattern[str]: |
| 280 | + return re.compile(rf"\.\.\. {get_all_directives()}::") |
| 281 | + |
275 | 282 |
|
276 | 283 | # Find role used with double backticks instead of simple backticks like: |
277 | 284 | # :const:``None`` |
|
0 commit comments