plugin
This module contains the "mkdocstrings" plugin for MkDocs.
The plugin instantiates a Markdown extension (MkdocstringsExtension
),
and adds it to the list of Markdown extensions used by mkdocs
during the on_config
event hook.
Once the documentation is built, the on_post_build
event hook
is triggered and calls the handlers.teardown()
method. This method is
used to teardown the handlers that were instantiated during documentation buildup.
Finally, when serving the documentation, it can add directories to watch
during the on_serve
event hook.
RENDERING_OPTS_KEY: str = 'rendering'
module-attribute
¤
The name of the rendering parameter in YAML configuration blocks.
SELECTION_OPTS_KEY: str = 'selection'
module-attribute
¤
The name of the selection parameter in YAML configuration blocks.
MkdocstringsPlugin()
¤
Bases: BasePlugin
An mkdocs
plugin.
This plugin defines the following event hooks:
on_config
on_env
on_post_build
on_serve
Check the Developing Plugins page of mkdocs
for more information about its plugin system.
Source code in mkdocstrings/plugin.py
108 109 110 111 |
|
config_scheme: Tuple[Tuple[str, MkType]] = (('watch', MkType(list, default=[])), ('handlers', MkType(dict, default={})), ('default_handler', MkType(str, default='python')), ('custom_templates', MkType(str, default=None)), ('enable_inventory', MkType(bool, default=None)), ('enabled', MkType(bool, default=True)))
class-attribute
¤
The configuration options of mkdocstrings
, written in mkdocs.yml
.
Available options are:
watch
(deprecated): A list of directories to watch. Only used when serving the documentation with mkdocs. Whenever a file changes in one of directories, the whole documentation is built again, and the browser refreshed. Deprecated in favor of the now built-inwatch
feature of MkDocs.default_handler
: The default handler to use. The value is the name of the handler module. Default is "python".enabled
: Whether to enable the plugin. Default is true. If false, mkdocstrings will not collect or render anything.handlers
: Global configuration of handlers. You can set global configuration per handler, applied everywhere, but overridable in each "autodoc" instruction. Example:
plugins:
- mkdocstrings:
handlers:
python:
options:
selection_opt: true
rendering_opt: "value"
rust:
options:
selection_opt: 2
handlers: Handlers
property
¤
Get the instance of mkdocstrings.handlers.base.Handlers for this plugin/build.
Raises:
Type | Description |
---|---|
RuntimeError
|
If the plugin hasn't been initialized with a config. |
Returns:
Type | Description |
---|---|
Handlers
|
An instance of mkdocstrings.handlers.base.Handlers (the same throughout the build). |
inventory_enabled: bool
property
¤
Tell if the inventory is enabled or not.
Returns:
Type | Description |
---|---|
bool
|
Whether the inventory is enabled. |
plugin_enabled: bool
property
¤
get_handler(handler_name)
¤
Get a handler by its name. See mkdocstrings.handlers.base.Handlers.get_handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handler_name |
str
|
The name of the handler. |
required |
Returns:
Type | Description |
---|---|
BaseHandler
|
An instance of a subclass of |
Source code in mkdocstrings/plugin.py
303 304 305 306 307 308 309 310 311 312 |
|
on_config(config, **kwargs)
¤
Instantiate our Markdown extension.
Hook for the on_config
event.
In this hook, we instantiate our MkdocstringsExtension
and add it to the list of Markdown extensions used by mkdocs
.
We pass this plugin's configuration dictionary to the extension when instantiating it (it will need it later when processing markdown to get handlers and their global configurations).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
The MkDocs config object. |
required |
**kwargs |
Any
|
Additional arguments passed by MkDocs. |
{}
|
Returns:
Type | Description |
---|---|
Config
|
The modified config. |
Source code in mkdocstrings/plugin.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
on_env(env, config, *args, **kwargs)
¤
Extra actions that need to happen after all Markdown rendering and before HTML rendering.
Hook for the on_env
event.
- Write mkdocstrings' extra files into the site dir.
- Gather results from background inventory download tasks.
Source code in mkdocstrings/plugin.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
on_post_build(config, **kwargs)
¤
Teardown the handlers.
Hook for the on_post_build
event.
This hook is used to teardown all the handlers that were instantiated and cached during documentation buildup.
For example, a handler could open a subprocess in the background and keep it open
to feed it "autodoc" instructions and get back JSON data. If so, it should then close the subprocess at some point:
the proper place to do this is in the collector's teardown
method, which is indirectly called by this hook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Config
|
The MkDocs config object. |
required |
**kwargs |
Any
|
Additional arguments passed by MkDocs. |
{}
|
Source code in mkdocstrings/plugin.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
on_serve(server, config, builder, *args, **kwargs)
¤
Watch directories.
Hook for the on_serve
event.
In this hook, we add the directories specified in the plugin's configuration to the list of directories
watched by mkdocs
. Whenever a change occurs in one of these directories, the documentation is built again
and the site reloaded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server |
LiveReloadServer
|
The |
required |
config |
Config
|
The MkDocs config object (unused). |
required |
builder |
Callable
|
The function to build the site. |
required |
*args |
Any
|
Additional arguments passed by MkDocs. |
()
|
**kwargs |
Any
|
Additional arguments passed by MkDocs. |
{}
|
Source code in mkdocstrings/plugin.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
list_to_tuple(function)
¤
Decorater to convert lists to tuples in the arguments.
Source code in mkdocstrings/plugin.py
45 46 47 48 49 50 51 52 53 54 |
|