Build step
DocBuilder renders a node tree into a
BuildOutput: pages (Markdown of one flavour), assets, the nav as
NavItem tree and the Markdown extensions / CSS / JS the
pages need. MarkdownExporter writes it as plain Markdown
files plus a SUMMARY.md nav. The site generator (mknodes build) does the same and
then runs Zensical, so this is only needed to use MkNodes without it.
Example
import mknodes as mk
nav = mk.MkNav()
page = nav.add_page("Usage", is_index=True)
page += mk.MkAdmonition("Install with `pip install mknodes`.", typ="tip")
output = mk.DocBuilder(flavor="github").build(nav)
mk.MarkdownExporter().export(output, "site/") # index.md + SUMMARY.md
mknodes.DocBuilder
class DocBuilder
Renders a node tree (root MkNav + optional theme) into a BuildOutput.
For each page: render the Markdown in the chosen flavour, collect its resources,
wire up its page template and optionally render it with Jinja. Afterwards the
resources of all pages (+ theme) get turned into assets, stylesheets, scripts and
Markdown extensions, and the nav into a NavItem tree.
mknodes.BuildOutput
class BuildOutput
Everything a node tree produced, independent of the target.
Pages are rendered in one Markdown flavour (see mknodes.rendering). Exporters /
site generators turn this into files or into the input of a static site engine.
mknodes.build.output.NavItem
class NavItem
An entry of the site navigation.
Either a link to a page / URL (target set) or a section (children set).
target
target: str | None = None
Page path (relative to the docs root) or an external URL.
mknodes.MarkdownExporter
class MarkdownExporter
Writes the pages and assets plus the nav as SUMMARY.md.
The result is readable in any Markdown viewer (and on GitHub, with the github
flavour). SUMMARY.md uses the literate-nav format.
Page info
Code for this page
mknodes.manual.api_section.add_page.
@nav.route.page(title, hide="toc")
def _(page: mk.MkPage) -> None:
page += INTROS[title]
page += mk.MkCode(EXAMPLES[title].rstrip(), language="py", title="Example")
for identifier in identifiers:
page += mk.MkDocStrings(identifier, **DOCSTRING_OPTIONS)
Resources
Resources(css=[],
markdown_extensions={},
plugins=[],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/api_section.py
source_function: _add_page.<locals>._
source_line_no: 168
hide:
- toc
title: Build step