MkHtmlBlock

github Show source on GitHub

PyMdown-based Html block. Can be used to show raw content.

Example: Regular

Jinja

{{ "Different types." | MkHtmlBlock("div") }}

Python

MkHtmlBlock(content='Different types.', block_type='div', attributes={'markdown': None})

Different types.

<div>

Different types.

</div>
<div>
<p>Different types.</p>
</div>
<div>

Different types.

</div>
MkHtmlBlock
╰── MkText('Different types.')

class MkHtmlBlock(mkblock.MkBlock)

Name

Children

Inherits

MkBlock
mknodes.basenodes.mkblock
PyMdown-based block.

graph TD
  2214384146["mkhtmlblock.MkHtmlBlock"]
  1483073837["mkblock.MkBlock"]
  835538629["mkcontainer.MkContainer"]
  1956333208["mkcontainer.MkContainerBase"]
  1359323199["mknode.MkNode"]
  2751680898["builtins.object"]
  1483073837 --> 2214384146
  835538629 --> 1483073837
  1956333208 --> 835538629
  1359323199 --> 1956333208
  2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkhtmlblock/metadata.toml
[metadata]
icon = "octicon:code-16"
name = "MkHtmlBlock"

[requirements.extension."pymdownx.blocks.html"]

[examples.regular]
title = "Regular"
jinja = """
{{ "Different types." | MkHtmlBlock("div") }}
"""

[output.markdown]
template = """
{{ node.fence_boundary }} html{% if node.argument %}{{ node.argument | add(prefix=' | ')}}{% endif %}
{{ node.attributes_block }}

{{ node.get_content_block() }}{{ node.fence_boundary }}

"""
mknodes.basenodes.mkhtmlblock.MkHtmlBlock
20class MkHtmlBlock(mkblock.MkBlock):
21    """PyMdown-based Html block. Can be used to show raw content."""
22
23    ICON = "octicons/code-16"
24    REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.blocks.html")]
25
26    def __init__(
27        self,
28        content: str | mknode.MkNode = "",
29        block_type: BlockTypeStr = "div",
30        *,
31        markdown_mode: MarkdownModeStr | None = None,
32        attributes: dict[str, Any] | None = None,
33        **kwargs: Any,
34    ) -> None:
35        """Constructor.
36
37        Args:
38            content: What should be contained in the block
39            block_type: Block type
40            markdown_mode: Markdown mode
41            attributes: Block attrs
42            kwargs: Keyword arguments passed to parent
43        """
44        super().__init__(
45            name="html",
46            argument=block_type,
47            content=content,
48            attributes=attributes,
49            **kwargs,
50        )
51        self.markdown_mode = markdown_mode
52
53    def __repr__(self) -> str:
54        items = self.get_items()
55        content = (
56            reprhelpers.to_str_if_textnode(items[0])
57            if len(items) == 1
58            else [reprhelpers.to_str_if_textnode(i) for i in items]
59        )
60        return reprhelpers.get_repr(
61            self,
62            content=content,
63            block_type=self.argument,
64            markdown_mode=self.markdown_mode,
65            attributes=self.attributes,
66            _filter_empty=True,
67        )
68
69    @property
70    def markdown_mode(self) -> MarkdownModeStr | None:
71        """The markdown mode attribute."""
72        return self.attributes.get("markdown")
73
74    @markdown_mode.setter
75    def markdown_mode(self, value: MarkdownModeStr | None) -> None:
76        self.attributes["markdown"] = value
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: octicons/code-16
title: MkHtmlBlock