Skip to content

MkReprRawRendered

:fa-brands-github: Show source on GitHub

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()

Info

Some text

MkAdmonition(None)
!!! info
    Some text
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Some text</p>
</div>

Info

Some text

MkAdmonition
╰── MkText('Some text')
!!! info
    Some text


===! "Repr"
    ```` {.python }
    MkAdmonition(None)
    ````

=== "Raw"
    ```` {.markdown }
    !!! info
        Some text

    ````

=== "Html"
    ```` {.html }
    <div class="admonition info">
    <p class="admonition-title">Info</p>
    <p>Some text</p>
    </div>
    ````

===+ "Rendered"
    !!! info
        Some text

=== "Repr tree"
    ````
    MkAdmonition
    ╰── MkText('Some text')
    ````
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Some text</p>
</div>
<div class="tabbed-set" data-tabs="1:5"><input id="__tabbed_1_1" name="__tabbed_1" type="radio"><label for="__tabbed_1_1">Repr</label><div class="tabbed-content">
<div class="language-python highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="n">MkAdmonition</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
</span></code></pre></div>
</div>
<input id="__tabbed_1_2" name="__tabbed_1" type="radio"><label for="__tabbed_1_2">Raw</label><div class="tabbed-content">
<div class="language-markdown highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a>!!! info
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a>    Some text
</span></code></pre></div>
</div>
<input id="__tabbed_1_3" name="__tabbed_1" type="radio"><label for="__tabbed_1_3">Html</label><div class="tabbed-content">
<div class="language-html highlight"><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="p">&lt;</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">"admonition info"</span><span class="p">&gt;</span>
</span><span id="__span-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">"admonition-title"</span><span class="p">&gt;</span>Info<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span><span id="__span-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>Some text<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span><span id="__span-2-4"><a id="__codelineno-2-4" name="__codelineno-2-4" href="#__codelineno-2-4"></a><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
</span></code></pre></div>
</div>
<input checked id="__tabbed_1_4" name="__tabbed_1" type="radio"><label for="__tabbed_1_4">Rendered</label><div class="tabbed-content">
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Some text</p>
</div>
</div>
<input id="__tabbed_1_5" name="__tabbed_1" type="radio"><label for="__tabbed_1_5">Repr tree</label><div class="tabbed-content">
<div class="language-text highlight"><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a>MkAdmonition
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a>╰── MkText('Some text')
</span></code></pre></div>
</div>
</div>
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 info">\n<p class="admonition-title">Info</p>\n<p>Some text</p>\n</div>')
    ├── MkTab(title='Rendered', content=MkAdmonition(None), select=True)
    │   ╰── MkAdmonition(None)
    │       ╰── MkText('Some text')
    ╰── MkTab(title='Repr tree', content=MkTreeView(MkAdmonition(None)))
        ╰── MkTreeView(MkAdmonition(None))

Bases: MkTemplate

__init__

__init__(node: MkNode | str | None = None, **kwargs: Any) -> None

Parameters:

Name Type Description Default
node MkNode | str | None

Node to show an example for

None
kwargs Any

Keyword arguments passed to parent

{}
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
class MkReprRawRendered(mktemplate.MkTemplate):
    """Node showing a tabbed block to visualize a node in different representations.

    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.
    """

    ICON = "material/presentation"

    def __init__(self, node: mknode.MkNode | str | None = None, **kwargs: Any) -> None:
        """Constructor.

        Args:
            node: Node to show an example for
            kwargs: Keyword arguments passed to parent
        """
        self._node = node
        super().__init__("output/markdown/template", **kwargs)

    def get_mknode(self) -> mk.MkNode | None:
        match self._node:
            case None:
                return None
            case str():
                return self.env.render_nodes(string=self._node).children[0]
            case _:
                return self._node
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
def create_section_for_nodes(
    nav: mk.MkNav,
    klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
    for kls in klasses:
        tpl = "classpage_custom.jinja"
        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
        nav += page
        if kls.STATUS:
            page.metadata.status = kls.STATUS
        elif kls.JS_FILES:
            page.metadata.status = "js"
        elif kls.CSS:
            page.metadata.status = "css"
        page.created_by = create_section_for_nodes
        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
        table.add_row((link, kls.__doc__, extensions))
    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 0x785e0f644250>,
                                                                           '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