Skip to content

Commit dde46cf

Browse files
committed
fix(docs-autogen): scale source-link icon with heading font size
mdxify hardcodes `style="width: 14px; height: 14px;"` on the GitHub Icon component. Inline styles win over the stylesheet, so the icon rendered at a fixed 14 px regardless of whether it appeared in an h2, h3, or h4 heading. Add a `normalize_icon_size` pass to decorate_api_mdx.py that replaces the pixel dimensions with `0.85em` so the icon scales with the surrounding heading's font size. Remove the now-redundant CSS width/height rules on `article h* sup svg` — the inline style is the single source of truth for icon sizing. Also add a mypy override to suppress the pre-existing import-not-found error for `cpex`, a private optional dependency not available in all environments. Assisted-by: Claude Code
1 parent 2c2ed7e commit dde46cf

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

docs/src/css/custom.css

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,10 @@ pre code {
115115
font-weight: 600;
116116
}
117117

118-
/* API headings: inline GitHub source icon — de-superscript and scale to text size */
118+
/* API headings: inline GitHub source icon — de-superscript; size set via em inline style */
119119
article h2 sup,
120120
article h3 sup,
121121
article h4 sup {
122122
vertical-align: middle;
123123
font-size: 1em;
124124
}
125-
article h2 sup svg,
126-
article h3 sup svg,
127-
article h4 sup svg {
128-
width: 0.9em;
129-
height: 0.9em;
130-
}

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ disable_error_code = [
312312
"import-not-found",
313313
]
314314

315+
[[tool.mypy.overrides]]
316+
# cpex is a private optional dependency not available in all environments
317+
module = "cpex.*"
318+
ignore_missing_imports = true
319+
315320

316321
# -----------------------------
317322
# Codespell - Spell Checking

tooling/docs-autogen/decorate_api_mdx.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
Decoration passes (applied in order per file):
1313
1. fix_source_links — correct GitHub blob URLs to versioned tags
14+
1b. normalize_icon_size — replace mdxify's hardcoded 14px icon style with em units
1415
2. inject_preamble — add per-module introductory text
1516
3. inject_sidebar_fix — insert SidebarFix Mintlify component
1617
4. escape_mdx_syntax — escape {{ }} in code blocks so MDX doesn't treat them as JSX
@@ -123,6 +124,32 @@ def replace_md(match):
123124
return content
124125

125126

127+
# =========================
128+
# Icon size normalisation
129+
# =========================
130+
131+
_ICON_PX_RE = re.compile(
132+
r'(<Icon\b[^>]*\bstyle=")width:\s*\d+px;\s*height:\s*\d+px;("[^>]*/?>)'
133+
)
134+
135+
136+
def normalize_icon_size(content: str) -> str:
137+
"""Replace mdxify's hardcoded pixel icon sizes with em units.
138+
139+
mdxify emits ``style="width: 14px; height: 14px;"`` on source-link Icon
140+
components. Inline styles take priority over the stylesheet, so the icon
141+
renders at a fixed 14 px regardless of heading level. Swapping to ``em``
142+
units lets the icon scale with the surrounding heading font-size.
143+
144+
Args:
145+
content: MDX file content.
146+
147+
Returns:
148+
Content with pixel icon dimensions replaced by ``0.85em``.
149+
"""
150+
return _ICON_PX_RE.sub(r"\g<1>width: 0.85em; height: 0.85em;\g<2>", content)
151+
152+
126153
# =========================
127154
# RST double-backtick normalisation
128155
# =========================
@@ -856,6 +883,9 @@ def process_mdx_file(
856883
# Step 1: Fix GitHub source links
857884
text = fix_source_links(text, version)
858885

886+
# Step 1b: Replace mdxify's hardcoded 14px icon sizes with em units
887+
text = normalize_icon_size(text)
888+
859889
# Step 2: Inject preamble (docstring cache text may also contain RST notation;
860890
# inject_preamble runs after normalize so the injected text needs a second pass)
861891
text = inject_preamble(text, module_path, docstring_cache)

0 commit comments

Comments
 (0)