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.
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
¶
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.
__init__
¶
__init__(
*,
flavor: str | Renderer | None = None,
render_jinja: bool = True,
show_page_info: bool = False,
global_resources: bool = True,
max_workers: int | None = None
) -> None
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flavor
|
str | Renderer | None
|
Markdown flavour to render (default: the active renderer, Material). |
None
|
render_jinja
|
bool
|
Render pages with their Jinja environment (pages can opt out
with the |
True
|
show_page_info
|
bool
|
Append a collapsible box with build info to every page
(pages can override with the |
False
|
global_resources
|
bool
|
Collect page CSS / JS for the whole site. If False, they get moved into the page templates (only these pages load them). |
True
|
max_workers
|
int | None
|
Render pages in that many threads (default: sequentially). |
None
|
build
¶
build(root: MkNav, theme: Theme | None = None) -> BuildOutput
Render given tree.
Rendering is sync and never fetches: the inputs of the nodes get resolved first,
inputs found while rendering between render passes (see mknodes.inputs).
Problems which don't stop the build (failed nodes, broken code fences, ...) get
logged and collected in BuildOutput.diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
MkNav
|
Root nav of the tree. |
required |
theme
|
Theme | None
|
Theme whose resources, templates and extras get included. |
None
|
mknodes.BuildOutput
dataclass
¶
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.
assets
class-attribute
instance-attribute
¶
Static files: path relative to the docs root -> content (CSS, JS, images, ...).
diagnostics
class-attribute
instance-attribute
¶
Problems reported while building (failed nodes / blocks, broken fences, references).
edit_paths
class-attribute
instance-attribute
¶
Page path -> repository path of the source that generated it.
extra
class-attribute
instance-attribute
¶
Theme variables (extra in MkDocs / Zensical configs).
extra_css
class-attribute
instance-attribute
¶
Stylesheets: URLs or paths relative to the docs root (contained in assets).
extra_javascript
class-attribute
instance-attribute
¶
Scripts: URLs or paths relative to the docs root (contained in assets).
flavor
class-attribute
instance-attribute
¶
Markdown flavour the pages are rendered in.
markdown_extensions
class-attribute
instance-attribute
¶
Python-Markdown extensions required by the pages: name -> config.
metadata
class-attribute
instance-attribute
¶
Site metadata inferred from the project.
nav
class-attribute
instance-attribute
¶
nav: list[NavItem] = dataclasses.field(default_factory=list)
Navigation tree.
page_resources
class-attribute
instance-attribute
¶
Page path -> resources required by that page.
pages
class-attribute
instance-attribute
¶
Markdown pages: path relative to the docs root -> Markdown.
templates
class-attribute
instance-attribute
¶
Theme template overrides (Material-style Jinja blocks): filename -> template.
mknodes.build.output.NavItem
dataclass
¶
An entry of the site navigation.
Either a link to a page / URL (target set) or a section (children set).
target
class-attribute
instance-attribute
¶
Page path (relative to the docs root) or an external URL.
mknodes.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.
__init__
¶
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_file
|
str | None
|
Filename for the nav (None: don't write the nav). |
SUMMARY_FILE
|
export
¶
export(output: BuildOutput, target: str | PathLike[str]) -> None
Write the files of given output into target folder (local path or fsspec URL).
get_files
¶
get_files(output: BuildOutput) -> dict[str, str | bytes]
Return all files to write: path relative to the target -> content.