MCPcopy
hub / github.com/Python-Markdown/markdown / ReferenceProcessor

Class ReferenceProcessor

markdown/blockprocessors.py:577–603  ·  view source on GitHub ↗

Process link references.

Source from the content-addressed store, hash-verified

575
576
577class 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
606class ParagraphProcessor(BlockProcessor):

Callers 1

build_block_parserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…