Skip to content

MkHtmlBlock

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.

/// html | div


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

Bases: MkBlock

markdown_mode property writable

markdown_mode: MarkdownModeStr | None

__init__

__init__(
    content: str | mknode.MkNode = "",
    block_type: BlockTypeStr = "div",
    *,
    markdown_mode: MarkdownModeStr | None = None,
    attributes: dict[str, Any] | None = None,
    **kwargs: Any
)

Parameters:

Name Type Description Default
content str | MkNode

What should be contained in the block

''
block_type BlockTypeStr

Block type

'div'
markdown_mode MarkdownModeStr | None

Markdown mode

None
attributes dict[str, Any] | None

Block attrs

None
kwargs Any

Keyword arguments passed to parent

{}
Name Children Inherits
MkBlock
mknodes.basenodes.mkblock
PyMdown-based block.
graph TD
  94854582922720["mkhtmlblock.MkHtmlBlock"]
  94854582920960["mkblock.MkBlock"]
  94854582919984["mkcontainer.MkContainer"]
  94854582916880["mknode.MkNode"]
  94854582838576["node.Node"]
  140544995341632["builtins.object"]
  94854582920960 --> 94854582922720
  94854582919984 --> 94854582920960
  94854582916880 --> 94854582919984
  94854582838576 --> 94854582916880
  140544995341632 --> 94854582838576
/home/runner/work/mknodes/mknodes/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.content_block }}{{ node.fence_boundary }}

"""
mknodes.basenodes.mkhtmlblock.MkHtmlBlock
class MkHtmlBlock(mkblock.MkBlock):
    """PyMdown-based Html block. Can be used to show raw content."""

    ICON = "octicons/code-16"
    REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.blocks.html")]

    def __init__(
        self,
        content: str | mknode.MkNode = "",
        block_type: BlockTypeStr = "div",
        *,
        markdown_mode: MarkdownModeStr | None = None,
        attributes: dict[str, Any] | None = None,
        **kwargs: Any,
    ):
        """Constructor.

        Arguments:
            content: What should be contained in the block
            block_type: Block type
            markdown_mode: Markdown mode
            attributes: Block attrs
            kwargs: Keyword arguments passed to parent
        """
        super().__init__(
            name="html",
            argument=block_type,
            content=content,
            attributes=attributes,
            **kwargs,
        )
        self.markdown_mode = markdown_mode

    def __repr__(self):
        if len(self.items) == 1:
            content = reprhelpers.to_str_if_textnode(self.items[0])
        else:
            content = [reprhelpers.to_str_if_textnode(i) for i in self.items]
        return reprhelpers.get_repr(
            self,
            content=content,
            block_type=self.argument,
            markdown_mode=self.markdown_mode,
            attributes=self.attributes,
            _filter_empty=True,
        )

    @property
    def markdown_mode(self) -> MarkdownModeStr | None:
        """The markdown mode attribute."""
        return self.attributes.get("markdown")

    @markdown_mode.setter
    def markdown_mode(self, value: MarkdownModeStr | None):
        self.attributes["markdown"] = value