Build and append footnote div to end of document.
| 417 | |
| 418 | |
| 419 | class FootnoteTreeprocessor(Treeprocessor): |
| 420 | """ Build and append footnote div to end of document. """ |
| 421 | |
| 422 | def __init__(self, footnotes: FootnoteExtension): |
| 423 | self.footnotes = footnotes |
| 424 | |
| 425 | def run(self, root: etree.Element) -> None: |
| 426 | footnotesDiv = self.footnotes.makeFootnotesDiv(root) |
| 427 | if footnotesDiv is not None: |
| 428 | result = self.footnotes.findFootnotesPlaceholder(root) |
| 429 | if result: |
| 430 | child, parent, isText = result |
| 431 | ind = list(parent).index(child) |
| 432 | if isText: |
| 433 | parent.remove(child) |
| 434 | parent.insert(ind, footnotesDiv) |
| 435 | else: |
| 436 | parent.insert(ind + 1, footnotesDiv) |
| 437 | child.tail = None |
| 438 | else: |
| 439 | root.append(footnotesDiv) |
| 440 | |
| 441 | |
| 442 | class FootnoteReorderingProcessor(Treeprocessor): |