extension
This module holds the code of the Markdown extension responsible for matching "autodoc" instructions.
The extension is composed of a Markdown block processor that matches indented blocks starting with a line like '::: identifier'.
For each of these blocks, it uses a handler to collect documentation about the given identifier and render it with Jinja templates.
Both the collection and rendering process can be configured by adding YAML configuration under the "autodoc" instruction:
::: some.identifier
handler: python
selection:
option1: value1
option2:
- value2a
- value2b
rendering:
option_x: etc
AutoDocProcessor(parser, md, config, handlers, autorefs)
¤
Bases: BlockProcessor
Our "autodoc" Markdown block processor.
It has a test
method that tells if a block matches a criterion,
and a run
method that processes it.
It also has utility methods allowing to get handlers and their configuration easily, useful when processing a matched block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser |
BlockParser
|
A |
required |
md |
Markdown
|
A |
required |
config |
dict
|
The configuration
of the |
required |
handlers |
Handlers
|
The handlers container. |
required |
autorefs |
AutorefsPlugin
|
The autorefs plugin instance. |
required |
Source code in mkdocstrings/extension.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
run(parent, blocks)
¤
Run code on the matched blocks.
The identifier and configuration lines are retrieved from a matched block and used to collect and render an object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
Element
|
The parent element in the XML tree. |
required |
blocks |
MutableSequence[str]
|
The rest of the blocks to be processed. |
required |
Source code in mkdocstrings/extension.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
test(parent, block)
¤
Match our autodoc instructions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
Element
|
The parent element in the XML tree. |
required |
block |
str
|
The block to be tested. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether this block should be processed or not. |
Source code in mkdocstrings/extension.py
78 79 80 81 82 83 84 85 86 87 88 |
|
MkdocstringsExtension(config, handlers, autorefs, **kwargs)
¤
Bases: Extension
Our Markdown extension.
It cannot work outside of mkdocstrings
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
dict
|
The configuration items from |
required |
handlers |
Handlers
|
The handlers container. |
required |
autorefs |
AutorefsPlugin
|
The autorefs plugin instance. |
required |
**kwargs |
Any
|
Keyword arguments used by |
{}
|
Source code in mkdocstrings/extension.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
extendMarkdown(md)
¤
Register the extension.
Add an instance of our AutoDocProcessor
to the Markdown parser.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
md |
Markdown
|
A |
required |
Source code in mkdocstrings/extension.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|