Markdown flavours¶
Nodes render to the Markdown of a flavour. The default flavour, material, is
Markdown for Material for MkDocs /
Zensical, using Python-Markdown / PyMdown extensions (admonitions, tabs, attribute
lists, …). The github flavour produces GitHub flavoured Markdown for READMEs, issues
and wikis: alerts, <details> blocks, <kbd> and plain fenced code. The mdbook
flavour is the GitHub flavour for mdBook
(optionally with mdbook-admonish admonitions), the myst flavour the GitHub flavour
with MyST directives (admonitions, dropdowns, tab sets, {code-block}) for Sphinx.
import mknodes as mk
node = mk.MkAdmonition("Careful!", typ="warning")
node.to_markdown() # Material (default)
node.to_markdown(flavor="github") # > [!WARNING] ...
A whole site can be generated in a flavour with the CLI. The markdown engine writes
plain Markdown files plus a SUMMARY.md nav and defaults to github:
mknodes generate --engine markdown --flavor github --generated-dir build/markdown
Each engine has a default flavour, see Site engines.
The flavour can also be set with the flavor setting (see
Configuration) or passed to
DocBuilder. The renderer classes are documented in
Core API / Rendering.
Side by side¶
Each node is shown as rendered on this site, followed by its Markdown in both flavours.
Admonition¶
Careful
Content with Markdown.
!!! warning "Careful"
Content with **Markdown**.
> [!WARNING]
> **Careful**
>
> Content with **Markdown**.
Collapsible admonition¶
Click me
Hidden until clicked.
??? info "Click me"
Hidden until clicked.
<details>
<summary>Click me</summary>
Hidden until clicked.
</details>
Tabs¶
import mknodes as mk
pip install mknodes
===! "Python"
``` {.py }
import mknodes as mk
```
=== "Shell"
``` {.bash }
pip install mknodes
```
<details open>
<summary>Python</summary>
```py
import mknodes as mk
```
</details>
<details>
<summary>Shell</summary>
```bash
pip install mknodes
```
</details>
Code block with title¶
import mknodes as mk
nav = mk.MkNav()
``` {.py title='build.py'}
import mknodes as mk
nav = mk.MkNav()
```
**build.py**
```py
import mknodes as mk
nav = mk.MkNav()
```
Keys¶
Ctrl+Alt+Del
++ctrl+alt+del++
<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Del</kbd>
Details block¶
More info
Some details.
/// details | More info
type: tip
Some details.
///
<details>
<summary>More info</summary>
Some details.
</details>
Definition list¶
- MkNav
-
A section of the documentation.
- MkPage
-
A page of the documentation.
MkNav
: A section of the documentation.
MkPage
: A page of the documentation.
<dl>
<dt>MkNav</dt>
<dd>
A section of the documentation.
</dd>
<dt>MkPage</dt>
<dd>
A page of the documentation.
</dd>
</dl>
Critic markup¶
Inserted text
{++
Inserted text
++}
<ins>
Inserted text
</ins>
Progress bar¶
██████░░░░ 60%
[=60% "60%"]
`██████░░░░` 60%
Link with icon¶
[:mdi-github: Repository](https://github.com/phil65/mknodes)
[<img src="https://api.iconify.design/mdi/github.svg?height=16" alt="github"> Repository](https://github.com/phil65/mknodes)
Material badge¶
4.1.0
<span class="md-typeset mdx-badge">
<span class="mdx-badge__icon">:mdi-tag:</span>
<span class="mdx-badge__text">4.1.0</span>
</span>
<img src="https://api.iconify.design/mdi/tag.svg?height=16" alt="tag"> <code>4.1.0</code>
Docstrings¶
mknodes.rendering.github.alert¶
def alert(typ: str, text: str, title: str | None = None) -> str
Return a GitHub alert block (> [!NOTE]).
::: mknodes.rendering.github.alert
options:
heading_level: 4
show_root_heading: True
#### <a id="mknodes.rendering.github.alert"></a>`mknodes.rendering.github.alert`
```python
def alert(typ: str, text: str, title: str | None = None) -> str
```
Return a GitHub alert block (`> [!NOTE]`).
GitHub rules¶
How the github flavour renders each node. A node either has a rule (a render
function registered with GithubRenderer.rule, also used for subclasses which don’t
render themselves), an [output.github] template in its node file, or renders its
default Markdown, the same as in the material flavour. That is fine for plain
Markdown (text, tables, lists); output that needs Markdown extensions (last column) may
not display on GitHub. Containers rendering their default Markdown still render their
children in the GitHub flavour, and hand-written Material admonitions / tabs in page text
get converted.
Node |
GitHub output |
Details |
Extensions of the Material output |
|---|---|---|---|
Rule |
|
||
Default |
|
||
Rule |
A shields.io badge image (GitHub drops inline SVG). |
||
Template of |
|
||
|
Rule |
Unknown PyMdown blocks: keep the content, drop the block. |
|
Default |
|||
Default |
|||
Default |
|||
Rule of |
Fenced code block with plain language info string (no attributes). |
|
|
Default |
|
||
Default |
|||
Rule |
Fenced code block with plain language info string (no attributes). |
|
|
Default |
|||
Default |
|||
Default |
|||
Default |
|||
Rule |
|||
Default |
|||
Default |
|||
Rule |
|
||
|
Default |
||
Rule |
|
||
|
Default |
|
|
Default |
|
||
Rule |
|
||
|
Default |
||
Default |
|||
Rule of |
Fenced code block with plain language info string (no attributes). |
|
|
Rule |
API docs rendered from Griffe (GitHub has no mkdocstrings). |
||
Default |
|
||
Default |
|||
Rule |
The element itself ( |
|
|
Rule |
HTML table with unescaped Markdown cells (Material: |
||
Default |
|||
Rule |
|||
Template |
|
||
Default |
|||
Default |
|||
Default |
|||
Default |
|||
|
Default |
||
Rule |
|
||
Default |
|||
Rule |
|||
Default |
|
||
Default |
|||
Rule |
|||
Default |
|||
Default |
|
||
Rule of |
Fenced code block with plain language info string (no attributes). |
|
|
Rule |
|
||
Default |
|||
|
Default |
||
|
Default |
||
Default |
|||
Default |
|||
Default |
|||
Rule |
|||
|
Rule |
|
|
|
Rule |
|
|
|
Rule |
Tabs become |
|
Rule of |
Tabs become |
|
|
Rule of |
Tabs become |
|
|
Default |
|
||
Default |
|
||
Default |
|||
Default |
|||
Default |
|||
Rule of |
Fenced code block with plain language info string (no attributes). |
|
Page info
Code for this page
123@nav.route.page("Markdown flavours", icon="material/language-markdown")
124def _(page: mk.MkPage) -> None:
125 documented = [
126 *BASE_NODES,
127 *IMAGE_NODES,
128 *PRESENTATION_NODES,
129 *DOCUMENTATION_NODES,
130 *ABOUT_THE_PROJECT_NODES,
131 *CONTAINER_NODES,
132 *SPECIAL_NODES,
133 ]
134 flavors.build_page(page, documented)
Resources
Resources(css=[],
markdown_extensions={'md_in_html': {}, 'tables': {}},
plugins=[],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: _
source_line_no: 123
icon: material/language-markdown
title: Markdown flavours