Plugins in Python #
The lsdocs-plugin package (import lsdocs_plugin) registers handlers
by decorator (its API reference: lsdocs_plugin
and lsdocs_plugin.testing, generated
from its source). Each handler gets the request's params, as dicts shaped like
the protocol, and a context:
=
=
=
return
Use it from the site's configuration:
[[]]
= "shout"
= "python"
= "shout"
lsdocs runs it as python -m shout in the project directory (set
LSDOCS_PYTHON to use another interpreter).
Handlers #
| Decorator | Handles |
|---|---|
@plugin.parse(extensions=["txt"]) | Parsing; return the document, or {"document", "diagnostics"}. |
@plugin.read | parse/transform/each: reads each document; return any value. |
@plugin.transform(nodes=[...]) | render/transform/each: changes each document; params["collected"] has what read returned for every document. Return the document. |
@plugin.render(formats=["html"]) | Rendering; return a str or bytes. |
@plugin.render_all | Files no single page makes (render/transform/all); return a list of {"path", "output"}. |
Handlers may be async def; coroutines share one event loop. Handlers run
one at a time unless Plugin("x", "1.0", max_concurrency=8) lets more
overlap. The context has ctx.project (directory and source files) and
ctx.site (title and base URL), and sends logs, progress and
diagnostics.
A plugin's settings are files it reads from the site's .config/
directory: name them with config_files, {name} standing for the
plugin's name in lsdocs.toml. They are read when the session starts;
ctx.settings maps each to its text (None if missing), for the plugin to
parse, and ctx.config has dir and name:
=
=
=
=
...
Testing #
lsdocs_plugin.testing calls handlers in-process, as lsdocs would:
, =
assert ==