Theming
A build function receives the theme next to the root nav. Theme holds the template overrides, CSS and the error page, MaterialTheme adds Material for MkDocs settings (palette, colors, content width, status icons).
import mknodes as mk
def build(root: mk.MkNav, theme: mk.Theme) -> mk.MkNav:
theme.error_page.content = mk.MkAdmonition("Page does not exist!")
if isinstance(theme, mk.MaterialTheme):
theme.content_area_width = 1300
page = root.add_page("Home", is_index=True)
page += "Hello"
return root
mknodes.Theme
¶
MkDocs Theme.
primary_color
property
¶
Return the primary color of the theme.
Can be overridden by subclasses.
text_color
property
¶
Return the text color of the theme.
Can be overridden by subclasses.
__init__
¶
Instanciate the theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The theme name |
required |
data
|
dict[str, Any] | None
|
Additional data for the theme |
None
|
adapt_extensions
¶
Make adaptions to markdown extensions for the theme if required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extensions
|
MutableMapping[str, dict[str, Any]]
|
The extensions to adapt |
required |
adapt_extras
¶
Adapt the "extras" dictionary containing additional information.
add_admonition_type
¶
add_admonition_type(
name: str,
icon: str,
header_color: ColorType,
icon_color: ColorType | None = None,
border_color: ColorType | None = None,
font_color: ColorType | None = None,
) -> None
Add a custom admonition type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Slug for new admonition type |
required |
icon
|
str
|
Either a Pyconify icon key or an |
required |
header_color
|
ColorType
|
Color for the admonition header |
required |
icon_color
|
ColorType | None
|
Color for the admonition icon |
None
|
border_color
|
ColorType | None
|
Color for the admonition border |
None
|
font_color
|
ColorType | None
|
Color for the admonition header font |
None
|
get_css_context
¶
Return variables used to resolve the CSS template.
Can be overridden by subclasses.
get_resources
async
¶
Return resources required for the theme.
Usually, the resources consist of static templates and CSS.
get_theme
classmethod
¶
Return theme instance of corresponding subclass based on theme name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme_name
|
str
|
Name of the theme |
'material'
|
data
|
dict[str, Any] | None
|
Additional data for the theme |
None
|
kwargs
|
Any
|
Additional keyword arguments passe to the Theme |
{}
|
mknodes.MaterialTheme
¶
Bases: Theme
Material Theme.
alternate_selector
instance-attribute
¶
Layout: - name: English link: /en/ lang: en
adapt_extensions
¶
MkDocs-Material needs some custom configuration for extensions.
This method will get called during the build process in order to make sure that theme-specifics are considered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extensions
|
MutableMapping[str, dict]
|
Extensions to adapt. |
required |
add_status_icon
¶
Add a custom status icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
slug for the status icon |
required |
icon
|
str
|
Iconify icon name |
required |
description
|
str | None
|
Optional status description (used for tooltip) |
None
|
add_tag
¶
Add a page tag.
The tag identifier must be set in page metadata. This requires the "tags" plugin to be included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Slug for the tag |
required |
tag
|
str
|
Tag name |
required |
icon
|
str | None
|
Optional Iconify icon identifier |
None
|
get_css_context
¶
Return template context (used to render the CSS template.
set_accent_foreground_color
¶
Set the accent foreground color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
RGBColorType
|
Color to set |
required |
set_default_icon
¶
Allows setting some custom default icons used throughout the theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
icon_type
|
IconTypeStr
|
Icon type to set a new default for |
required |
data
|
str
|
svg for the new icon |
required |
set_primary_background_color
¶
Set the primary background color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
RGBColorType
|
Color to set |
required |
set_primary_foreground_color
¶
set_primary_foreground_color(
color: ColorType,
light_shade: ColorType | None = None,
dark_shade: ColorType | None = None,
)
Set a custom color theme.
Requires primary color set to "custom".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
ColorType
|
Main color |
required |
light_shade
|
ColorType | None
|
Optional light shade. If None, same as color. |
None
|
dark_shade
|
ColorType | None
|
Optional dark shade. If None, same as color. |
None
|
Page info
Code for this page
| mknodes.manual.api_section._add_page.<locals>._ | |
|---|---|