Process link references.
| 575 | |
| 576 | |
| 577 | class ReferenceProcessor(BlockProcessor): |
| 578 | """ Process link references. """ |
| 579 | RE = re.compile( |
| 580 | r'^[ ]{0,3}\[([^\[\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$', re.MULTILINE |
| 581 | ) |
| 582 | |
| 583 | def test(self, parent: etree.Element, block: str) -> bool: |
| 584 | return True |
| 585 | |
| 586 | def run(self, parent: etree.Element, blocks: list[str]) -> bool: |
| 587 | block = blocks.pop(0) |
| 588 | m = self.RE.search(block) |
| 589 | if m: |
| 590 | id = m.group(1).strip().lower() |
| 591 | link = m.group(2).lstrip('<').rstrip('>') |
| 592 | title = m.group(5) or m.group(6) |
| 593 | self.parser.md.references[id] = (link, title) |
| 594 | if block[m.end():].strip(): |
| 595 | # Add any content after match back to blocks as separate block |
| 596 | blocks.insert(0, block[m.end():].lstrip('\n')) |
| 597 | if block[:m.start()].strip(): |
| 598 | # Add any content before match back to blocks as separate block |
| 599 | blocks.insert(0, block[:m.start()].rstrip('\n')) |
| 600 | return True |
| 601 | # No match. Restore block. |
| 602 | blocks.insert(0, block) |
| 603 | return False |
| 604 | |
| 605 | |
| 606 | class ParagraphProcessor(BlockProcessor): |
no outgoing calls
no test coverage detected
searching dependent graphs…