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 = "",
    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
  94721311700000["mkhtmlblock.MkHtmlBlock"]
  94721311698224["mkblock.MkBlock"]
  94721311697232["mkcontainer.MkContainer"]
  94721308848336["mknode.MkNode"]
  94721311766592["node.Node"]
  140564252373184["builtins.object"]
  94721311698224 --> 94721311700000
  94721311697232 --> 94721311698224
  94721308848336 --> 94721311697232
  94721311766592 --> 94721308848336
  140564252373184 --> 94721311766592
/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.

        Args:
            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