Add pieces to Markdown.
(self, md)
| 83 | self.reset() |
| 84 | |
| 85 | def extendMarkdown(self, md): |
| 86 | """ Add pieces to Markdown. """ |
| 87 | md.registerExtension(self) |
| 88 | self.parser = md.parser |
| 89 | self.md = md |
| 90 | # Insert a `blockprocessor` before `ReferencePreprocessor` |
| 91 | md.parser.blockprocessors.register(FootnoteBlockProcessor(self), 'footnote', 17) |
| 92 | |
| 93 | # Insert an inline pattern before `ImageReferencePattern` |
| 94 | FOOTNOTE_RE = r'\[\^([^\]]*)\]' # blah blah [^1] blah |
| 95 | md.inlinePatterns.register(FootnoteInlineProcessor(FOOTNOTE_RE, self), 'footnote', 175) |
| 96 | # Insert a tree-processor that would actually add the footnote div |
| 97 | # This must be before all other tree-processors (i.e., `inline` and |
| 98 | # `codehilite`) so they can run on the the contents of the div. |
| 99 | md.treeprocessors.register(FootnoteTreeprocessor(self), 'footnote', 50) |
| 100 | |
| 101 | # Insert a tree-processor to reorder the footnotes if necessary. This must be after |
| 102 | # `inline` tree-processor so it can access the footnote reference order |
| 103 | # (`self.footnote_order`) that gets populated by the `FootnoteInlineProcessor`. |
| 104 | if not self.getConfig("USE_DEFINITION_ORDER"): |
| 105 | md.treeprocessors.register(FootnoteReorderingProcessor(self), 'footnote-reorder', 19) |
| 106 | |
| 107 | # Insert a tree-processor that will run after inline is done. |
| 108 | # In this tree-processor we want to check our duplicate footnote tracker |
| 109 | # And add additional `backrefs` to the footnote pointing back to the |
| 110 | # duplicated references. |
| 111 | md.treeprocessors.register(FootnotePostTreeprocessor(self), 'footnote-duplicate', 15) |
| 112 | |
| 113 | # Insert a postprocessor after amp_substitute processor |
| 114 | md.postprocessors.register(FootnotePostprocessor(self), 'footnote', 25) |
| 115 | |
| 116 | def reset(self) -> None: |
| 117 | """ Clear footnotes on reset, and prepare for distinct document. """ |
nothing calls this directly
no test coverage detected