MkMaterialBadge
:fa-brands-github: Show source on GitHub
Node for a CSS-based badge a la MkDocs-Material.¶
Example: Regular¶
:mdi-wrench: text
<p><span class="md-typeset mdx-badge">
<span class="mdx-badge__icon"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="m22.7 19l-9.1-9.1c.9-2.3.4-5-1.5-6.9c-2-2-5-2.4-7.4-1.3L9 6L6 9L1.6 4.7C.4 7.1.9 10.1 2.9 12.1c1.9 1.9 4.6 2.4 6.9 1.5l9.1 9.1c.4.4 1 .4 1.4 0l2.3-2.3c.5-.4.5-1.1.1-1.4"/></svg></span></span>
<span class="mdx-badge__text">text</span>
</span></p>
Example: Heart type¶
:mdi-file: text
<p><span class="md-typeset mdx-badge mdx-badge--heart">
<span class="mdx-badge__icon"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M13 9V3.5L18.5 9M6 2c-1.11 0-2 .89-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z"/></svg></span></span>
<span class="mdx-badge__text">text</span>
</span></p>
Example: Right aligned¶
:mdi-file: text
<p><span class="md-typeset mdx-badge mdx-badge--right">
<span class="mdx-badge__icon"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M13 9V3.5L18.5 9M6 2c-1.11 0-2 .89-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z"/></svg></span></span>
<span class="mdx-badge__text">text</span>
</span></p>
Example: With link¶
:mdi-file: text
<p><span class="md-typeset mdx-badge">
<span class="mdx-badge__icon"><a href="https://phil65.github.io/mknodes"><span class="twemoji"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M13 9V3.5L18.5 9M6 2c-1.11 0-2 .89-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z"/></svg></span></a></span>
<span class="mdx-badge__text">text</span>
</span></p>
Bases: MkTemplate
__init__
¶
__init__(
icon: str,
text: str = "",
*,
animated: bool = False,
align_right: bool = False,
target: LinkableType | None = None,
**kwargs: Any
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
icon
|
str
|
Icon to display. Can either be an iconify or an emoji slug |
required |
text
|
str
|
Text to display |
''
|
animated
|
bool
|
Optional animated style |
False
|
align_right
|
bool
|
Right-align badge |
False
|
target
|
LinkableType | None
|
An optional URL / page target for the badge |
None
|
kwargs
|
Any
|
Keyword arguments passed to parent |
{}
|
| Name | Children | Inherits |
|---|---|---|
| MkTemplate mknodes.templatenodes.mktemplate Node representing a jinja template. |
graph TD
3179977919["mkmaterialbadge.MkMaterialBadge"]
1289759389["mktemplate.MkTemplate"]
3160803176["rendercache.TemplateRenderMixin"]
2751680898["builtins.object"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
1289759389 --> 3179977919
3160803176 --> 1289759389
2751680898 --> 3160803176
835538629 --> 1289759389
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkmaterialbadge/metadata.toml
[metadata]
name = "MkMaterialBadge"
icon = "simple-icons:shieldsdotio"
group = "badge"
[[resources.css]]
filename = "materialbadge.css"
[examples.regular]
title = "Regular"
jinja = """
{{ "mdi:wrench" | MkMaterialBadge(text="text") }}
"""
[examples.heart_type]
title = "Heart type"
jinja = """
{{ "mdi:file" | MkMaterialBadge(text="text", animated=True) }}
"""
[examples.right_aligned]
title = "Right aligned"
jinja = """
{{ "mdi:file" | MkMaterialBadge(text="text", align_right=True) }}
"""
[examples.linked]
title = "With link"
jinja = """
{{ "mdi:file" | MkMaterialBadge(text="text", target="https://phil65.github.io/mknodes") }}
"""
[output.html]
template = """
<span class="md-typeset mdx-badge{{ " mdx-badge--right" if node.align_right else "" }}{{ " mdx-badge--heart" if node.animated else "" }}">
{% set icon = "[" ~ node.icon | get_emoji_slug ~ "](" ~ node.target | get_url ~ ")" if node.target else node.icon | get_emoji_slug %}
{% if node.icon %} <span class="mdx-badge__icon">{{ icon }}</span>
{% endif %}
{% if node.get_text() %} <span class="mdx-badge__text">{{ node.get_text() }}</span>
{% endif %}
</span>
"""
Page info
Code for this page
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 0x703933662e50>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[Asset('materialbadge_31c4bf6.css')],
packages=[])