Skip to content

Navs and pages

A documentation is a tree: MkNav objects are the sections, MkPage objects the pages, nodes the content of a page. Nodes get added with +=, navs and pages with add_nav() / add_page() (or via decorators, see Routing). The root nav is what a build function receives.

Example
import mknodes as mk

nav = mk.MkNav()  # the root nav
page = nav.add_page("Usage", is_index=True, hide="toc")
page += mk.MkAdmonition("Install with `pip install mknodes`.", typ="tip")
guides = nav.add_nav("Guides")
first_steps = guides.add_page("First steps")
first_steps += "Some text"

mknodes.MkNav

Bases: MkNode

Nav section, representing a nestable menu.

A nav is named (exception is the root nav, which has section name = None), has an associated virtual file (in general a SUMMARY.md), an optional index page and can contain other navs as well as pages and links.

index_page property writable

index_page: MkPage | None

Get the current index page if set.

metadata instance-attribute

metadata = metadata_.Metadata(metadata or {})

Page Metadata.

nav instance-attribute

nav = navigation.Navigation()

Navigation object containing all child items.

parse instance-attribute

parse = navparser.NavParser(self)

Parser object used to build Navs from different data / directory structures.

resolved_file_path property

resolved_file_path: str

Returns the resulting section/subsection/../filename.xyz path.

route instance-attribute

route = navrouter.NavRouter(self)

Router used for decorator routing.

__add__

__add__(other: NavSubType) -> Self

Use this to to register MkNodes.

__init__

__init__(
    section: str | None = None,
    *,
    filename: str = "SUMMARY.md",
    metadata: dict[str, Any] | None = None,
    **kwargs: Any
) -> None

Constructor.

Parameters:

Name Type Description Default
section str | None

Section name for the Nav

None
filename str

FileName for the resulting nav

'SUMMARY.md'
metadata dict[str, Any] | None

Metadata for the nav. Child pages will inherit this.

None
kwargs Any

Keyword arguments passed to parent

{}

add_doc

add_doc(
    module: ModuleType | Sequence[str] | str | None = None,
    *,
    filter_by___all__: bool = False,
    recursive: bool = False,
    section_name: str | None = None,
    class_template: str | None = None,
    module_template: str | None = None,
    flatten_nav: bool = False
) -> MkDoc

Add a module documentation to the Nav.

Parameters:

Name Type Description Default
module ModuleType | Sequence[str] | str | None

The module to create a documentation section for.

None
filter_by___all__ bool

Whether the documentation

False
recursive bool

Whether to search modules recursively

False
section_name str | None

Override the name for the menu (default: module name)

None
class_template str | None

Override for the default ClassPage template

None
module_template str | None

Override for the default ModulePage template

None
flatten_nav bool

Whether classes should be put into top-level of the nav

False

add_nav

add_nav(section: str) -> MkNav

Create a Sub-Nav, register it to given Nav and return it.

Parameters:

Name Type Description Default
section str

Name of the new nav.

required

add_page

add_page(
    title: str | None = None,
    *,
    is_index: bool = False,
    is_homepage: bool = False,
    path: str | None = None,
    hide: list[str] | str | None = None,
    search_boost: float | None = None,
    exclude_from_search: bool | None = None,
    icon: str | None = None,
    status: PageStatusStr | None = None,
    subtitle: str | None = None,
    description: str | None = None,
    template: str | None = None,
    tags: list[str] | None = None
) -> MkPage

Add a page to the Nav.

Parameters:

Name Type Description Default
title str | None

Page title

None
is_index bool

Whether the page should become the index page.

False
is_homepage bool

Whether the page should become the homepage.

False
path str | None

optional path override

None
hide list[str] | str | None

Hide parts of the page ("toc", "nav", "path")

None
search_boost float | None

multiplier for search ranking

None
exclude_from_search bool | None

Exclude page from search index

None
icon str | None

optional page icon

None
status PageStatusStr | None

Page status

None
subtitle str | None

Page subtitle

None
description str | None

Page description

None
template str | None

Page template

None
tags list[str] | None

tags to show above the main headline and within the search preview

None

get_children

get_children() -> list[NavSubType]

Return all child items from the navigation.

to_markdown async

to_markdown(flavor: str | Renderer | None = None) -> str

Return the nav as literate-nav Markdown (the same for every flavour).

mknodes.MkPage

Bases: MkContainer

A node container representing a Markdown page.

A page contains a list of other Markdown nodes, has a virtual Markdown file associated, and can have metadata (added as header)

created_by property writable

created_by: Callable[..., Any] | None

The function which created the page (like a route function).

icon property writable

icon: str | None

Return page icon from metadata.

path property writable

path: str

Return the last part of the page path.

resolved_file_path property

resolved_file_path: str

Returns the resulting section/subsection/../filename.xyz path.

resolved_metadata property

resolved_metadata: Metadata

Return page metadata, complemented with the parent Nav metadata objects.

status property writable

status: PageStatusStr | str | None

Return page status from metadata.

subtitle property writable

subtitle: str | None

Return subtitle from metadata.

title property writable

title: str

Return the page title if set, otherwise infer title from path.

__init__

__init__(
    title: str | None = None,
    *,
    hide: list[str] | str | None = None,
    search_boost: float | None = None,
    exclude_from_search: bool | None = None,
    icon: str | None = None,
    path: str | PathLike[str] | None = None,
    status: PageStatusStr | None = None,
    subtitle: str | None = None,
    description: str | None = None,
    template: str | PageTemplate | None = None,
    inclusion_level: bool | None = None,
    tags: list[str] | None = None,
    edit_path: str | None = None,
    is_index: bool | None = None,
    is_homepage: bool | None = None,
    **kwargs: Any
) -> None

Constructor.

Parameters:

Name Type Description Default
path str | PathLike[str] | None

Page path

None
hide list[str] | str | None

Hide parts of the website ("toc", "nav", "path", "tags").

None
search_boost float | None

Factor to modify search ranking

None
exclude_from_search bool | None

Whether to exclude this page from search listings

None
icon str | None

Optional page icon

None
status PageStatusStr | None

Page status

None
title str | None

Page title

None
subtitle str | None

Page subtitle

None
description str | None

Page description

None
template str | PageTemplate | None

Page template (filename relative to overrides directory or PageTemplate object)

None
inclusion_level bool | None

Inclusion level of the page

None
tags list[str] | None

tags to show above the main headline and within the search preview

None
edit_path str | None

Custom edit path for this page

None
kwargs Any

Keyword arguments passed to parent

{}
is_index bool | None

Whether this page should be the index page.

None
is_homepage bool | None

Whether this page should be the homepage.

None

from_file classmethod

from_file(
    path: str | PathLike[str],
    *,
    title: str | None = None,
    parent: MkNode | None = None,
    **kwargs: Any
) -> Self

Reads file content and creates an MkPage.

Parses and reads header metadata.

Parameters:

Name Type Description Default
path str | PathLike[str]

Path to load file from, either a local path or a fsspec protocol path.

required
title str | None

Optional title to use If None, title will be infered from metadata or filename

None
parent MkNode | None

Optional parent for new page

None
kwargs Any

Additional metadata for MkPage. Will override parsed metadata.

{}

get_processors

get_processors() -> list[TextProcessor]

Override base MkNode processors.

is_index

is_index() -> bool

Returns True if the page is the index page for the parent Nav.

Page info
Code for this page
mknodes.manual.api_section._add_page.<locals>._
@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={'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.superfences': {}},
          plugins=[Plugin('mkdocstrings')],
          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: Navs and pages