Module

rendering.plugins.directives.button

Button directive for Mistune.

Provides clean button syntax for CTAs and navigation.

Architecture:

Migrated to BengalDirective base class as part of directive system v2.

Classes

ButtonOptions dataclass
Options for button directive.
0

Options for button directive.

Inherits from DirectiveOptions

Attributes

Name Type Description
color str

Button color theme (primary, secondary, success, danger, etc.)

style str

Button style (default, pill, outline)

size str

Button size (small, medium, large)

icon str

Optional icon name

target str

Link target (_blank for external links)

_allowed_values ClassVar[dict[str, list[str]]]
ButtonDirective
Button directive for creating styled link buttons. Syntax: :::{button} /path/to/page/ :col…
3

Button directive for creating styled link buttons.

Syntax:

:::{button} /path/to/page/
:color: primary
:style: pill
:size: large
:icon: rocket
:target: _blank

Button Text
:::

Options:

color: primary, secondary, success, danger, warning, info, light, dark
style: default (rounded), pill (fully rounded), outline
size: small, medium (default), large
icon: Icon name (same as cards)
target: _blank for external links (optional)
Inherits from BengalDirective

Attributes

Name Type Description
NAMES ClassVar[list[str]]
TOKEN_TYPE ClassVar[str]
OPTIONS_CLASS ClassVar[type[DirectiveOptions]]
DIRECTIVE_NAMES ClassVar[list[str]]

Methods 2

parse_directive
Build button token from parsed components. Title is the URL, content is the bu…
5 DirectiveToken
def parse_directive(self, title: str, options: ButtonOptions, content: str, children: list[Any], state: Any) -> DirectiveToken

Build button token from parsed components.

Title is the URL, content is the button text. Note: Uses 'label' instead of 'text' to avoid conflict with mistune's render signature which passes text as positional argument.

Parameters 5
title str
options ButtonOptions
content str
children list[Any]
state Any
Returns

DirectiveToken

render
Render button as HTML link. Renders as an <a> tag with button styling classes.…
2 str
def render(self, renderer: Any, text: str, **attrs: Any) -> str

Render button as HTML link.

Renders as an <a> tag with button styling classes.

Note: Button text is in attrs['label'] (not 'text') to avoid conflict with mistune's render signature.

Parameters 2
renderer Any
text str
Returns

str

Internal Methods 1
_render_icon staticmethod
Render icon for button using Bengal SVG icons.
2 str
def _render_icon(icon_name: str, button_text: str = '') -> str

Render icon for button using Bengal SVG icons.

Parameters 2
icon_name str

Name of the icon to render

button_text str

Button text (for warning context)

Returns

str

SVG HTML string, or empty string if not found

Functions

render_button
Legacy render function for backward compatibility.
2 str
def render_button(renderer: Any, text: str, **attrs: Any) -> str

Legacy render function for backward compatibility.

Parameters 2

Name Type Default Description
renderer Any
text str

Returns

str