Tutorial¶
Working usage examples¶
setup() registers the extension with Sphinx:
add_node()registersBadgeNodewith HTML visitors (visit_badge_html/depart_badge_html).add_css_file()injects the sharedsphinx_ux_badges.cssstylesheet.Downstream extensions call
setup_extension()to load the badge layer:
def setup(app: Sphinx) -> dict[str, Any]:
app.setup_extension("sphinx_ux_badges")
BadgeNode subclasses docutils.nodes.inline, so unregistered
builders (text, LaTeX, man) fall back to visit_inline via Sphinx’s
MRO-based dispatch — no special handling needed.
Build a grouped toolbar in your own directive or transform:
from sphinx_ux_badges import build_badge, build_badge_group, build_toolbar
badge_group = build_badge_group(
[
build_badge(
"readonly",
tooltip="Read-only operation",
classes=["gp-sphinx-fastmcp__safety-readonly"],
),
build_badge(
"tool",
tooltip="FastMCP tool entry",
classes=["gp-sphinx-fastmcp__type-tool"],
),
],
)
toolbar = build_toolbar(badge_group, classes=["my-extension-toolbar"])