Skip to content

Commit c729553

Browse files
committed
docs(style): Strip badges from sidebar via SphinxContentsFilter
Monkeypatch SphinxContentsFilter to raise SkipNode for all badge node types (_safety_badge_node, _resource_badge_node, _model_badge_node). This is the same pattern Sphinx uses for visit_image in titles. Badges stay inside nodes.title for proper heading rendering, but are stripped during toctree text extraction so the sidebar shows clean tool names without badge text or emoji leakage. Add CSS to size badges at 0.5em within h1/h2 headings for medium button appearance rather than full-scale heading text.
1 parent 84c2cfd commit c729553

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

docs/_ext/fastmcp_autodoc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,19 @@ def setup(app: Sphinx) -> ExtensionMetadata:
19971997
# CSS
19981998
app.add_css_file("css/fastmcp_autodoc.css")
19991999

2000+
# Strip badge nodes from toctree/sidebar title extraction.
2001+
# SphinxContentsFilter walks title nodes to build toctree text.
2002+
# Without this, badges inside titles propagate to the sidebar.
2003+
# This is the same pattern Sphinx uses for visit_image (SkipNode).
2004+
from sphinx.transforms import SphinxContentsFilter
2005+
2006+
def _skip_badge(self: t.Any, node: nodes.Node) -> None:
2007+
raise nodes.SkipNode
2008+
2009+
SphinxContentsFilter.visit__safety_badge_node = _skip_badge # type: ignore[attr-defined]
2010+
SphinxContentsFilter.visit__resource_badge_node = _skip_badge # type: ignore[attr-defined]
2011+
SphinxContentsFilter.visit__model_badge_node = _skip_badge # type: ignore[attr-defined]
2012+
20002013
return {
20012014
"version": "0.1.0",
20022015
"parallel_read_safe": True,

docs/_static/css/fastmcp_autodoc.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ span.sd-badge[aria-label*="model"] {
1818
font-family: var(--sd-fontfamily-monospace, monospace);
1919
}
2020

21+
/* Badge in section headings — medium size, not full h1 scale */
22+
h1 .sd-badge,
23+
h2 .sd-badge {
24+
font-size: 0.5em;
25+
vertical-align: middle;
26+
}
27+
28+
/* Sidebar: strip background from inline code (tool/resource/model names) */
29+
.sidebar-tree code.literal {
30+
background: none;
31+
}
32+
2133
/* Field/param table polish — tighter padding */
2234
.fastmcp-autodoc-table td,
2335
.fastmcp-autodoc-table th {

0 commit comments

Comments
 (0)