MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / FootnoteInlineProcessor

Class FootnoteInlineProcessor

markdown/extensions/footnotes.py:346–373  ·  view source on GitHub ↗

`InlineProcessor` for footnote markers in a document's body text.

Source from the content-addressed store, hash-verified

344
345
346class FootnoteInlineProcessor(InlineProcessor):
347 """ `InlineProcessor` for footnote markers in a document's body text. """
348
349 def __init__(self, pattern: str, footnotes: FootnoteExtension):
350 super().__init__(pattern)
351 self.footnotes = footnotes
352
353 def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]:
354 id = m.group(1)
355 if id in self.footnotes.footnotes.keys():
356 self.footnotes.addFootnoteRef(id)
357
358 if not self.footnotes.getConfig("USE_DEFINITION_ORDER"):
359 # Order by reference
360 footnote_num = self.footnotes.footnote_order.index(id) + 1
361 else:
362 # Order by definition
363 footnote_num = list(self.footnotes.footnotes.keys()).index(id) + 1
364
365 sup = etree.Element("sup")
366 a = etree.SubElement(sup, "a")
367 sup.set('id', self.footnotes.makeFootnoteRefId(id, found=True))
368 a.set('href', '#' + self.footnotes.makeFootnoteId(id))
369 a.set('class', 'footnote-ref')
370 a.text = self.footnotes.getConfig("SUPERSCRIPT_TEXT").format(footnote_num)
371 return sup, m.start(0), m.end(0)
372 else:
373 return None, None, None
374
375
376class FootnotePostTreeprocessor(Treeprocessor):

Callers 1

extendMarkdownMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected