|
47 | 47 | # Pattern to match figure references in HTML.
|
48 | 48 | P_FIGURE_REFS = re.compile(r'<img[^>]+src="([^"]+)"[^>]*>')
|
49 | 49 |
|
| 50 | +# Pattern to match internally-defined Markdown links. |
| 51 | +P_INTERNALLY_DEFINED_LINK = re.compile(r'\[[^\]]+\]\[[^\]]+\]') |
| 52 | + |
50 | 53 | # What kinds of blockquotes are allowed?
|
51 | 54 | KNOWN_BLOCKQUOTES = {
|
52 | 55 | 'callout',
|
@@ -274,6 +277,7 @@ def check(self):
|
274 | 277 | self.check_trailing_whitespace()
|
275 | 278 | self.check_blockquote_classes()
|
276 | 279 | self.check_codeblock_classes()
|
| 280 | + self.check_defined_link_references() |
277 | 281 |
|
278 | 282 |
|
279 | 283 | def check_metadata(self):
|
@@ -331,6 +335,26 @@ def check_codeblock_classes(self):
|
331 | 335 | cls)
|
332 | 336 |
|
333 | 337 |
|
| 338 | + def check_defined_link_references(self): |
| 339 | + """Check that defined links resolve in the file. |
| 340 | +
|
| 341 | + Internally-defined links match the pattern [text][label]. If |
| 342 | + the label contains '{{...}}', it is hopefully a references to |
| 343 | + a configuration value - we should check that, but don't right |
| 344 | + now. |
| 345 | + """ |
| 346 | + |
| 347 | + result = set() |
| 348 | + for node in self.find_all(self.doc, {'type' : 'text'}): |
| 349 | + for match in P_INTERNALLY_DEFINED_LINK.findall(node['value']): |
| 350 | + if '{{' not in match: |
| 351 | + result.add(match) |
| 352 | + self.reporter.check(not result, |
| 353 | + self.filename, |
| 354 | + 'Internally-defined links may be missing definitions: {0}', |
| 355 | + ', '.join(sorted(result))) |
| 356 | + |
| 357 | + |
334 | 358 | def find_all(self, node, pattern, accum=None):
|
335 | 359 | """Find all matches for a pattern."""
|
336 | 360 |
|
|
0 commit comments