Skip to content

MkCritic

Show source on GitHub

MkCritic block.

Example: Addition

Jinja

{{ "Type `addition`" | MkCritic(typ="addition") }}

Python

MkCritic('Type `addition`', typ='addition')

Type addition



Type `addition`


<ins class="critic block">
<p>Type <code>addition</code></p>
</ins>
MkCritic
╰── MkText('Type `addition`')

Example: Deletion

Jinja

{{ "Type `deletion`" | MkCritic(typ="deletion") }}

Python

MkCritic('Type `deletion`', typ='deletion')

Type deletion



Type `deletion`


<del class="critic block">
<p>Type <code>deletion</code></p>
</del>
MkCritic
╰── MkText('Type `deletion`')

Example: Highlight

Jinja

{{ "Type `highlight`" | MkCritic(typ="highlight") }}

Python

MkCritic('Type `highlight`')

Type highlight



Type `highlight`


<mark class="critic block">
<p>Type <code>highlight</code></p>
</mark>
MkCritic
╰── MkText('Type `highlight`')

Example: Comment

Jinja

{{ "Type `comment`" | MkCritic(typ="comment") }}

Python

MkCritic('Type `comment`', typ='comment')
Type `comment`
          Type `comment`          
<span class="critic comment">  Type `comment`  </span>
MkCritic
╰── MkText('Type `comment`')

Bases: MkContainer

__init__

__init__(
    content: str | MkNode | list, *, typ: CriticMarkStr = "highlight", **kwargs: Any
)

Parameters:

Name Type Description Default
content str | MkNode | list

Content to mark

required
typ CriticMarkStr

Mark type

'highlight'
kwargs Any

Keyword arguments passed to parent

{}
Name Children Inherits
MkContainer
mknodes.basenodes.mkcontainer
A node containing other MkNodes.
graph TD
  94721311938992["mkcritic.MkCritic"]
  94721311697232["mkcontainer.MkContainer"]
  94721308848336["mknode.MkNode"]
  94721311766592["node.Node"]
  140564252373184["builtins.object"]
  94721311697232 --> 94721311938992
  94721308848336 --> 94721311697232
  94721311766592 --> 94721308848336
  140564252373184 --> 94721311766592
/home/runner/work/mknodes/mknodes/mknodes/basenodes/mkcritic/metadata.toml
[metadata]
icon = "mdi:format-text"
name = "MkCritic"

[requirements.extension."pymdownx.critic"]

[examples.addition]
title = "Addition"
jinja = """
{{ "Type `addition`" | MkCritic(typ="addition") }}
"""

[examples.deletion]
title = "Deletion"
jinja = """
{{ "Type `deletion`" | MkCritic(typ="deletion") }}
"""

[examples.highlight]
title = "Highlight"
jinja = """
{{ "Type `highlight`" | MkCritic(typ="highlight") }}
"""

[examples.comment]
title = "Comment"
jinja = """
{{ "Type `comment`" | MkCritic(typ="comment") }}
"""

[output.markdown]
template = """
{% raw %}{{% endraw %}{{ node.marks[0] }}

{{ node.items | join(node.block_separator) }}

{{ node.marks[1] }}{% raw %}}{% endraw %}
"""
mknodes.basenodes.mkcritic.MkCritic
class MkCritic(mkcontainer.MkContainer):
    """MkCritic block."""

    ICON = "material/format-text"
    REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.critic")]

    def __init__(
        self,
        content: str | mk.MkNode | list,
        *,
        typ: CriticMarkStr = "highlight",
        **kwargs: Any,
    ):
        """Constructor.

        Args:
            content: Content to mark
            typ: Mark type
            kwargs: Keyword arguments passed to parent
        """
        super().__init__(content=content, **kwargs)
        self.typ = typ

    @property
    def marks(self):
        match self.typ:
            case "addition":
                return ("++", "++")
            case "deletion":
                return ("--", "--")
            case "highlight":
                return ("==", "==")
            case "comment":
                return (">>", "<<")
            case _:
                raise TypeError(self.typ)

    def _to_markdown(self) -> str:
        left, right = self.marks
        return f"{{{left}\n\n{super()._to_markdown()}\n\n{right}}}"