MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / extendMarkdown

Method extendMarkdown

markdown/extensions/footnotes.py:86–127  ·  view source on GitHub ↗

Register the processors. | Class Instance | Registry | Name | Priority | | --------------------------------------------------------------------------- | ----------

(self, md)

Source from the content-addressed store, hash-verified

84 self.reset()
85
86 def extendMarkdown(self, md):
87 """ Register the processors.
88
89 | Class Instance | Registry | Name | Priority |
90 | --------------------------------------------------------------------------- | ---------------------------------------------------------------- | ------ | :------: |
91 | [`FootnoteBlockProcessor`][markdown.extensions.footnotes.FootnoteBlockProcessor] | [`blockprocessors`][markdown.blockprocessors.build_block_parser] | `footnote` | `17` |
92 | [`FootnoteInlineProcessor`][markdown.extensions.footnotes.FootnoteInlineProcessor] | [`inlinepatterns`][markdown.inlinepatterns.build_inlinepatterns] | `footnote` | `175` |
93 | [`FootnoteTreeprocessor`][markdown.extensions.footnotes.FootnoteTreeprocessor] | [`treeprocessors`][markdown.treeprocessors.build_treeprocessors] | `footnote` | `50` |
94 | [`FootnoteReorderingProcessor`][markdown.extensions.footnotes.FootnoteReorderingProcessor] | [`treeprocessors`][markdown.treeprocessors.build_treeprocessors] | `footnote-reorder` | `19` |
95 | [`FootnotePostTreeprocessor`][markdown.extensions.footnotes.FootnotePostTreeprocessor] | [`treeprocessors`][markdown.treeprocessors.build_treeprocessors] | `footnote-duplicate` | `15` |
96 | [`FootnotePostprocessor`][markdown.extensions.footnotes.FootnotePostprocessor] | [`postprocessors`][markdown.postprocessors.build_postprocessors] | `footnote` | `25` |
97
98 """
99 # flake8: noqa: E501 88-95
100 md.registerExtension(self)
101 self.parser = md.parser
102 self.md = md
103 # Insert a `blockprocessor` before `ReferencePreprocessor`
104 md.parser.blockprocessors.register(FootnoteBlockProcessor(self), 'footnote', 17)
105
106 # Insert an inline pattern before `ImageReferencePattern`
107 FOOTNOTE_RE = r'\[\^([^\]]*)\]' # blah blah [^1] blah
108 md.inlinePatterns.register(FootnoteInlineProcessor(FOOTNOTE_RE, self), 'footnote', 175)
109 # Insert a tree-processor that would actually add the footnote div
110 # This must be before all other tree-processors (i.e., `inline` and
111 # `codehilite`) so they can run on the contents of the div.
112 md.treeprocessors.register(FootnoteTreeprocessor(self), 'footnote', 50)
113
114 # Insert a tree-processor to reorder the footnotes if necessary. This must be after
115 # `inline` tree-processor so it can access the footnote reference order
116 # (`self.footnote_order`) that gets populated by the `FootnoteInlineProcessor`.
117 if not self.getConfig("USE_DEFINITION_ORDER"):
118 md.treeprocessors.register(FootnoteReorderingProcessor(self), 'footnote-reorder', 19)
119
120 # Insert a tree-processor that will run after inline is done.
121 # In this tree-processor we want to check our duplicate footnote tracker
122 # And add additional `backrefs` to the footnote pointing back to the
123 # duplicated references.
124 md.treeprocessors.register(FootnotePostTreeprocessor(self), 'footnote-duplicate', 15)
125
126 # Insert a postprocessor after amp_substitute processor
127 md.postprocessors.register(FootnotePostprocessor(self), 'footnote', 25)
128
129 def reset(self) -> None:
130 """ Clear footnotes on reset, and prepare for distinct document. """

Callers

nothing calls this directly

Calls 9

registerExtensionMethod · 0.80
registerMethod · 0.80
getConfigMethod · 0.80

Tested by

no test coverage detected