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.
Classes:
-
MkdocstringsPlugin
–An
mkdocs
plugin.
Functions:
-
list_to_tuple
–Decorater to convert lists to tuples in the arguments.
MkdocstringsPlugin ¤
MkdocstringsPlugin()
Bases: BasePlugin
An mkdocs
plugin.
This plugin defines the following event hooks:
on_config
on_env
on_post_build
Check the Developing Plugins page of mkdocs
for more information about its plugin system.
Methods:
-
get_handler
–Get a handler by its name. See mkdocstrings.handlers.base.Handlers.get_handler.
-
on_config
–Instantiate our Markdown extension.
-
on_env
–Extra actions that need to happen after all Markdown rendering and before HTML rendering.
-
on_post_build
–Teardown the handlers.
Attributes:
-
config_scheme
(tuple[tuple[str, Type]]
) –The configuration options of
mkdocstrings
, written inmkdocs.yml
. -
handlers
(Handlers
) –Get the instance of mkdocstrings.handlers.base.Handlers for this plugin/build.
-
inventory_enabled
(bool
) –Tell if the inventory is enabled or not.
-
plugin_enabled
(bool
) –Tell if the plugin is enabled or not.
Source code in src/mkdocstrings/plugin.py
113 114 115 116 |
|
config_scheme class-attribute
instance-attribute
¤
config_scheme: tuple[tuple[str, Type]] = (
("handlers", Type(dict, default={})),
("default_handler", Type(str, default="python")),
("custom_templates", Type(str, default=None)),
("enable_inventory", Type(bool, default=None)),
("enabled", Type(bool, default=True)),
)
The configuration options of mkdocstrings
, written in mkdocs.yml
.
Available options are:
handlers
: Global configuration of handlers. You can set global configuration per handler, applied everywhere, but overridable in each "autodoc" instruction. Example:default_handler
: The default handler to use. The value is the name of the handler module. Default is "python".custom_templates
: Custom templates to use when rendering API objects.enable_inventory
: Whether to enable object inventory creation.enabled
: Whether to enable the plugin. Default is true. If false, mkdocstrings will not collect or render anything.
plugins:
- mkdocstrings:
handlers:
python:
options:
option1: true
option2: "value"
rust:
options:
option9: 2
handlers property
¤
handlers: Handlers
Get the instance of mkdocstrings.handlers.base.Handlers for this plugin/build.
Raises:
-
RuntimeError
–If the plugin hasn't been initialized with a config.
Returns:
-
Handlers
–An instance of mkdocstrings.handlers.base.Handlers (the same throughout the build).
get_handler ¤
get_handler(handler_name: str) -> BaseHandler
Get a handler by its name. See mkdocstrings.handlers.base.Handlers.get_handler.
Parameters:
-
handler_name
(str
) –The name of the handler.
Returns:
-
BaseHandler
–An instance of a subclass of
BaseHandler
.
Source code in src/mkdocstrings/plugin.py
288 289 290 291 292 293 294 295 296 297 |
|
on_config ¤
on_config(config: MkDocsConfig) -> MkDocsConfig | None
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:
-
config
(MkDocsConfig
) –The MkDocs config object.
Returns:
-
MkDocsConfig | None
–The modified config.
Source code in src/mkdocstrings/plugin.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 |
|
on_env ¤
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 src/mkdocstrings/plugin.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
on_post_build ¤
on_post_build(config: Config, **kwargs: Any) -> None
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 handler's teardown
method, which is indirectly called by this hook.
Parameters:
-
config
(Config
) –The MkDocs config object.
-
**kwargs
(Any
, default:{}
) –Additional arguments passed by MkDocs.
Source code in src/mkdocstrings/plugin.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
list_to_tuple ¤
Decorater to convert lists to tuples in the arguments.
Source code in src/mkdocstrings/plugin.py
53 54 55 56 57 58 59 60 61 62 |
|