`InlineProcessor` for footnote markers in a document's body text.
| 322 | |
| 323 | |
| 324 | class 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 | |
| 354 | class FootnotePostTreeprocessor(Treeprocessor): |
no outgoing calls
no test coverage detected
searching dependent graphs…