MkBadge
:fa-brands-github: Show source on GitHub
Node for a locally-created badge (based on "anybadge").¶
Description
The node creates a badge svg, appends it to the virtual files, and shows it as an image.
Example: Regular¶
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_37"> <rect width="86" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_37)"> <path fill="#555" d="M0 0h41v20H0z"/> <path fill="#4051b5" d="M41 0h45v20H41z"/> <path fill="url(#b)" d="M0 0h86v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="21.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="20.5" y="14">Some</text> </g> <g fill="#333333" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="64.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="63.5" y="14">Badge</text> </g></svg></body>
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_38"> <rect width="86" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_38)"> <path fill="#555" d="M0 0h41v20H0z"/> <path fill="#4c1" d="M41 0h45v20H41z"/> <path fill="url(#b)" d="M0 0h86v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="21.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="20.5" y="14">Some</text> </g> <g fill="" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="64.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="63.5" y="14">Badge</text> </g></svg></body>
Example: Font size¶
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_39"> <rect width="94" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_39)"> <path fill="#555" d="M0 0h45v20H0z"/> <path fill="#4051b5" d="M45 0h49v20H45z"/> <path fill="url(#b)" d="M0 0h94v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="23.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="22.5" y="14">Some</text> </g> <g fill="#333333" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="70.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="69.5" y="14">Badge</text> </g></svg></body>
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_40"> <rect width="94" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_40)"> <path fill="#555" d="M0 0h45v20H0z"/> <path fill="#4c1" d="M45 0h49v20H45z"/> <path fill="url(#b)" d="M0 0h94v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="23.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="22.5" y="14">Some</text> </g> <g fill="" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="70.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="69.5" y="14">Badge</text> </g></svg></body>
Example: Char padding¶
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="266" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_41"> <rect width="266" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_41)"> <path fill="#555" d="M0 0h131v20H0z"/> <path fill="#4051b5" d="M131 0h135v20H131z"/> <path fill="url(#b)" d="M0 0h266v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="66.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="65.5" y="14">Some</text> </g> <g fill="#333333" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="199.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="198.5" y="14">Badge</text> </g></svg></body>
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="266" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_42"> <rect width="266" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_42)"> <path fill="#555" d="M0 0h131v20H0z"/> <path fill="#4c1" d="M131 0h135v20H131z"/> <path fill="url(#b)" d="M0 0h266v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="66.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="65.5" y="14">Some</text> </g> <g fill="" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="199.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="198.5" y="14">Badge</text> </g></svg></body>
Example: Badge color¶
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_39"> <rect width="94" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_39)"> <path fill="#555" d="M0 0h45v20H0z"/> <path fill="#4051b5" d="M45 0h49v20H45z"/> <path fill="url(#b)" d="M0 0h94v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="23.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="22.5" y="14">Some</text> </g> <g fill="#333333" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="70.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="69.5" y="14">Badge</text> </g></svg></body>
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_40"> <rect width="94" height="20" rx="3" fill="#fff"/> </mask> <g mask="url(#anybadge_40)"> <path fill="#555" d="M0 0h45v20H0z"/> <path fill="#4c1" d="M45 0h49v20H45z"/> <path fill="url(#b)" d="M0 0h94v20H0z"/> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="23.5" y="15" fill="#010101" fill-opacity=".3">Some</text> <text x="22.5" y="14">Some</text> </g> <g fill="" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="12"> <text x="70.5" y="15" fill="#010101" fill-opacity=".3">Badge</text> <text x="69.5" y="14">Badge</text> </g></svg></body>
Example: GitLab style¶
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_43"> <rect width="86" height="20" rx="10" fill="#fff"/> </mask> <g mask="url(#anybadge_43)"> <path fill="#4051b5" d="M0 0h86v20H0z"/> <path fill="#262626" d="M41 2h36v16H41z"/> <path fill="#262626" d="M76,18 a1,1 0 0,0 0,-16"/> <path fill="url(#b)" d="M0 0h86v20H0z"/> </g> <g fill="#333333" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="20.5" y="14">Some</text> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="63.5" y="14">Badge</text> </g></svg></body>
<body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20" role="img" aria-label="Some: Badge"> <title>Some: Badge</title> <linearGradient id="b" x2="0" y2="100%"> <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> <stop offset="1" stop-opacity=".1"/> </linearGradient> <mask id="anybadge_44"> <rect width="86" height="20" rx="10" fill="#fff"/> </mask> <g mask="url(#anybadge_44)"> <path fill="#4c1" d="M0 0h86v20H0z"/> <path fill="#262626" d="M41 2h36v16H41z"/> <path fill="#262626" d="M76,18 a1,1 0 0,0 0,-16"/> <path fill="url(#b)" d="M0 0h86v20H0z"/> </g> <g fill="" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="20.5" y="14">Some</text> </g> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="63.5" y="14">Badge</text> </g></svg></body>
Bases: MkImage
__init__
¶
__init__(
label: str | tuple[str, str],
value: str | None = None,
*,
font_size: Literal[10, 11, 12] | None = None,
font_name: str | None = None,
num_padding_chars: int | None = None,
badge_color: str | None = None,
text_color: str | None = None,
use_gitlab_style: bool = False,
**kwargs: Any
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str | tuple[str, str]
|
Left part of the badge. If given a tuple, use 2nd item as value. |
required |
value
|
str | None
|
Right part of the badge |
None
|
font_size
|
Literal[10, 11, 12] | None
|
Size of font to use |
None
|
font_name
|
str | None
|
Name of font to use |
None
|
num_padding_chars
|
int | None
|
Number of chars to use for padding |
None
|
badge_color
|
str | None
|
Badge color |
None
|
text_color
|
str | None
|
Badge color |
None
|
use_gitlab_style
|
bool
|
Use Gitlab-scope style |
False
|
kwargs
|
Any
|
Keyword arguments passed to parent |
{}
|
| Name | Children | Inherits |
|---|---|---|
| MkImage mknodes.basenodes.mkimage Image including optional caption. |
graph TD
3610159806["mkbadge.MkBadge"]
4050704754["mkimage.MkImage"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
4050704754 --> 3610159806
1359323199 --> 4050704754
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/templatenodes/mkbadge/metadata.toml
[metadata]
icon = "simple-icons:shieldsdotio"
name = "MkBadge"
group = "badge"
[requirements.package.anybadge]
[examples.regular]
title = "Regular"
jinja = """
{{ ("Some", "Badge") | MkBadge }}
"""
[examples.font_size]
title = "Font size"
jinja = """
{{ ("Some", "Badge") | MkBadge(font_size=12) }}
"""
[examples.char_padding]
title = "Char padding"
jinja = """
{{ ("Some", "Badge") | MkBadge(num_padding_chars=5) }}
"""
[examples.badge_color]
title = "Badge color"
jinja = """
{{ ("Some", "Badge") | MkBadge(font_size=12) }}
"""
[examples.gitlab_style]
title = "GitLab style"
jinja = """
{{ ("Some", "Badge") | MkBadge(use_gitlab_style=True) }}
"""
[output.html]
template = """
<body>{{ node.get_data() | replace("\n", "") | html_link(node.get_url()) }}</body>
"""
| mknodes.templatenodes.mkbadge.MkBadge | |
|---|---|
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
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=[],
packages=[])