About¶
Introduction¶
md-transformer is a tool for MkDocs, Zensical, and a
standalone CLI tool
to execute code cells and thus create documentation dynamically.
The following code fence
will lead to the following output
After that you can execute the script within markdown using
which will be rendered as follows:
Including Python Source Code¶
You can also include the source code of any Python object (function, class, etc.) directly into your
documentation using the include-python code fence (see Technical
Details for how objects are resolved):
which will be rendered as follows:
def transform(fh_in, fh_out, transformers, max_line_length=100):
with MarkdownRenderer(max_line_length=max_line_length) as renderer:
text = expand_includes(fh_in.read())
doc = mistletoe.Document(text)
_transform(doc, list(transformers) + [FixLinebreak()])
print(renderer.render(doc), file=fh_out)
File Includes¶
You can include the content of external files directly into your documentation using the include
tag. The syntax is {% include path/to/file.md %}.
{% include path/to/file.md %}
This happens before any other transformations, allowing you to include files that themselves contain code fences or other macros.
More Information¶
For more details on how to integrate md-transformer into your projects and technical details on
its execution environment, please refer to the Usage guide.
Installation¶
To use the plugin you can install it using pip or uv: