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