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

Class FootnoteInlineProcessor

markdown/extensions/footnotes.py:324–351  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

322
323
324class FootnoteInlineProcessor(InlineProcessor):
325 """ `InlineProcessor` for footnote markers in a document's body text. """
326
327 def __init__(self, pattern: str, footnotes: FootnoteExtension):
328 super().__init__(pattern)
329 self.footnotes = footnotes
330
331 def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]:
332 id = m.group(1)
333 if id in self.footnotes.footnotes.keys():
334 self.footnotes.addFootnoteRef(id)
335
336 if not self.footnotes.getConfig("USE_DEFINITION_ORDER"):
337 # Order by reference
338 footnote_num = self.footnotes.footnote_order.index(id) + 1
339 else:
340 # Order by definition
341 footnote_num = list(self.footnotes.footnotes.keys()).index(id) + 1
342
343 sup = etree.Element("sup")
344 a = etree.SubElement(sup, "a")
345 sup.set('id', self.footnotes.makeFootnoteRefId(id, found=True))
346 a.set('href', '#' + self.footnotes.makeFootnoteId(id))
347 a.set('class', 'footnote-ref')
348 a.text = self.footnotes.getConfig("SUPERSCRIPT_TEXT").format(footnote_num)
349 return sup, m.start(0), m.end(0)
350 else:
351 return None, None, None
352
353
354class FootnotePostTreeprocessor(Treeprocessor):

Callers 1

extendMarkdownMethod · 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…