MkReprRawRendered¶
Node showing a tabbed block to visualize a node in different representations.¶
Description
It contains a tab for the repr, one for the rendered output, one for the markdown and a Repr tree in case the node has children. The node can also be a string with a jinja macro returning an MkNode. In that case a “Jinja” tab containing the macro is prepended to the other tabs.
Example: Regular
Jinja
{{ "Some text" | MkAdmonition | MkReprRawRendered }}
Python
MkContainer()
Note
Some text
Repr
MkAdmonition(None)
Raw
:::{note}
Some text
:::
Html
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Some text</p>
</div>
Rendered
Note
Some text
Repr tree
MkAdmonition
╰── MkText('Some text')
:::{note}
Some text
:::
:::{dropdown} Repr
````python
MkAdmonition(None)
````
:::
::::{dropdown} Raw
````markdown
:::{note}
Some text
:::
````
::::
:::{dropdown} Html
````html
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Some text</p>
</div>
````
:::
::::{dropdown} Rendered
:open:
:::{note}
Some text
:::
::::
:::{dropdown} Repr tree
````
MkAdmonition
╰── MkText('Some text')
````
:::
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Some text</p>
</div>
<details class="sd-dropdown">
<summary>Repr</summary>
<pre><code class="language-python">MkAdmonition(None)
</code></pre>
</details>
<details class="sd-dropdown">
<summary>Raw</summary>
<pre><code class="language-markdown">:::{note}
Some text
:::
</code></pre>
</details>
<details class="sd-dropdown">
<summary>Html</summary>
<pre><code class="language-html"><div class="admonition note">
<p class="admonition-title">Note</p>
<p>Some text</p>
</div>
</code></pre>
</details>
<details class="sd-dropdown" open>
<summary>Rendered</summary>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Some text</p>
</div>
</details>
<details class="sd-dropdown">
<summary>Repr tree</summary>
<pre><code>MkAdmonition
╰── MkText('Some text')
</code></pre>
</details>
MkContainer
╰── MkAdmonition(None)
╰── MkText('Some text')
╰── MkReprRawRendered(MkAdmonition(None))
├── MkTab(title='Repr', content=MkCode(None), new=True)
│ ╰── MkCode(None)
│ ╰── MkText('MkAdmonition(None)')
├── MkTab(title='Raw', content=MkCode(None, language='markdown'))
│ ╰── MkCode(None, language='markdown')
│ ╰── MkAdmonition(None)
│ ╰── MkText('Some text')
├── MkTab(title='Html', content=MkCode(None, language='html'))
│ ╰── MkCode(None, language='html')
│ ╰── MkText('<div class="admonition note">\n<p class="admonition-title">Note</p>\n<p>Some text</p>\n</div>\n')
├── MkTab(title='Rendered', content=MkAdmonition(None), select=True)
│ ╰── MkAdmonition(None)
│ ╰── MkText('Some text')
╰── MkTab(title='Repr tree', content=MkTreeView(MkAdmonition(None)))
╰── MkTreeView(MkAdmonition(None))
Name |
Children |
Inherits |
|---|---|---|
MkTemplate |
graph TD
3610119223["mkreprrawrendered.MkReprRawRendered"]
1289759389["mktemplate.MkTemplate"]
3160803176["rendercache.TemplateRenderMixin"]
2751680898["builtins.object"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
1289759389 --> 3610119223
3160803176 --> 1289759389
2751680898 --> 3160803176
835538629 --> 1289759389
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/templatenodes/mkreprrawrendered/metadata.toml¶
[metadata]
icon = "mdi:presentation"
name = "MkReprRawRendered"
group = "documentation"
virtual_children = true
[examples.regular]
title = "Regular"
jinja = """
{{ "Some text" | MkAdmonition | MkReprRawRendered }}
"""
[output.markdown]
template = """
{% set inspected = node.get_mknode() %}
{% if inspected %}
{% if node | getattr("_node") is string_like %}
{{ node | getattr("_node") | MkTab(title="Jinja") }}
{% endif %}
{{ inspected | repr | MkCode | MkTab(title="Repr", new=True) }}
{{ inspected | MkCode(language="markdown") | MkTab(title="Raw") }}
{{ inspected | to_html | MkCode(language="html") | MkTab(title="Html") }}
{{ inspected | MkTab(title="Rendered", select=True) }}
{% if inspected.get_children() %}
{{ inspected | MkTreeView | MkTab(title="Repr tree") }}{% endif %}{% endif %}
"""
mknodes.templatenodes.mkreprrawrendered.MkReprRawRendered¶
9class MkReprRawRendered(mktemplate.MkTemplate):
10 """Node showing a tabbed block to visualize a node in different representations.
11
12 It contains a tab for the repr, one for the rendered output,
13 one for the markdown and a Repr tree in case the node has children.
14 The node can also be a string with a jinja macro returning an MkNode.
15 In that case a "Jinja" tab containing the macro is prepended to the other tabs.
16 """
17
18 ICON = "material/presentation"
19
20 def __init__(self, node: mknode.MkNode | str | None = None, **kwargs: Any) -> None:
21 """Constructor.
22
23 Args:
24 node: Node to show an example for
25 kwargs: Keyword arguments passed to parent
26 """
27 self._node = node
28 super().__init__("output/markdown/template", **kwargs)
29
30 def get_mknode(self) -> mk.MkNode | None:
31 match self._node:
32 case None:
33 return None
34 case str():
35 return self.env.render_nodes(string=self._node).children[0]
36 case _:
37 return self._node
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes¶
93def create_section_for_nodes(
94 nav: mk.MkNav,
95 klasses: Sequence[type[mk.MkNode]],
96) -> mk.MkTable:
97 table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
98 for kls in klasses:
99 tpl = "classpage_custom.jinja"
100 page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
101 nav += page
102 if kls.STATUS:
103 page.metadata.status = kls.STATUS
104 elif kls.JS_FILES:
105 page.metadata.status = "js"
106 elif kls.CSS:
107 page.metadata.status = "css"
108 page.created_by = create_section_for_nodes
109 link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
110 extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
111 table.add_row((link, kls.__doc__, extensions))
112 return table
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7ff77e88b060>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: create_section_for_nodes
source_line_no: 93
hide:
- toc
icon: material/presentation
status: new
title: MkReprRawRendered