Module

rendering.plugins.badges

Badge plugin for Mistune.

Provides badge syntax: {bdg-color}text

Supports badge colors that map to Bengal's design system.

Classes

BadgePlugin
Mistune plugin for inline badge syntax. Syntax: {bdg-primary}`text` -> Primary color badg…
4

Mistune plugin for inline badge syntax.

Syntax:

{bdg-primary}`text`      -> Primary color badge
{bdg-secondary}`text`    -> Secondary/muted badge
{bdg-success}`text`      -> Success/green badge
{bdg-danger}`text`       -> Danger/red badge
{bdg-warning}`text`      -> Warning/yellow badge
{bdg-info}`text`         -> Info/blue badge
{bdg-light}`text`        -> Light badge
{bdg-dark}`text`         -> Dark badge

Maps to Bengal's CSS color system: bdg-primary -> badge-primary (blue) bdg-secondary -> badge-secondary (gray) bdg-success -> badge-success (green) bdg-danger -> badge-danger (red) bdg-warning -> badge-warning (yellow) bdg-info -> badge-info (blue) bdg-light -> badge-light (light gray) bdg-dark -> badge-dark (dark gray)

Compatibility: Full support for bdg-* roles.

Internal Methods 4
__init__
Initialize badge plugin.
0 None
def __init__(self) -> None

Initialize badge plugin.

__call__
Register the plugin with Mistune. Badge substitution happens in parser.py afte…
1 Any
def __call__(self, md: Any) -> Any

Register the plugin with Mistune.

Badge substitution happens in parser.py after HTML is generated. This method is required for Mistune plugin interface but does nothing.

Parameters 1
md Any
Returns

Any

_substitute_badges
Substitute {bdg-color}<code>text</code> patterns with badge HTML. Mistune conv…
1 str
def _substitute_badges(self, html: str) -> str

Substitute {bdg-color}<code>text</code> patterns with badge HTML.

Mistune convertstextto <code>text</code> before our plugin runs, so we match the HTML pattern: {bdg-color}<code>text</code>

Parameters 1
html str

HTML content that may contain badge patterns

Returns

str

HTML with badge patterns replaced by badge spans

_escape_html
Escape HTML special characters in badge text.
1 str
def _escape_html(self, text: str) -> str

Escape HTML special characters in badge text.

Parameters 1
text str

Badge text to escape

Returns

str

Escaped text