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.
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.
nav
instance-attribute
¶
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
¶
Returns the resulting section/subsection/../filename.xyz path.
__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
|
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
¶
The function which created the page (like a route function).
resolved_file_path
property
¶
Returns the resulting section/subsection/../filename.xyz path.
resolved_metadata
property
¶
Return page metadata, complemented with the parent Nav metadata objects.
__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 |
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. |
{}
|
Page info
Code for this page
| mknodes.manual.api_section._add_page.<locals>._ | |
|---|---|