Skip to content

docs(sphinx_fonts): add multi-subset support, Mono weights, latin-ext#1034

Merged
tony merged 3 commits intomasterfrom
sphinx-fonts
Mar 31, 2026
Merged

docs(sphinx_fonts): add multi-subset support, Mono weights, latin-ext#1034
tony merged 3 commits intomasterfrom
sphinx-fonts

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented Mar 31, 2026

Summary

  • Add IBM Plex Mono weights 500/600/700 (match Sans range)
  • Add multi-subset support with unicode-range descriptors to sphinx_fonts extension
  • Add latin-ext subset for both IBM Plex Sans and Mono
  • Add local docs/_ext/sphinx_fonts.py override with unicode-range support
  • Add 7 new tests for unicode-range and multi-subset functionality

Test plan

  • uv run py.test tests/docs/_ext/test_sphinx_fonts.py — 29 passed
  • uv run ruff check . — all checks passed
  • uv run mypy — no issues
  • Verify doc build renders fonts with proper weights

tony added 3 commits March 31, 2026 17:23
why: Only weight 400 was downloaded. Bold monospace text (badge labels at
font-weight 650, <strong> in code) used browser faux-bolding which looks
noticeably worse than the real typeface weights.

what:
- Match IBM Plex Sans weight range: [400, 500, 600, 700]
why: Only the "latin" subset was downloaded. Characters outside basic
Latin (accented letters like ñ, ř, ž common in contributor names and
code comments) fell back to system fonts, breaking the typographic
consistency of IBM Plex.

what:
- Add _UNICODE_RANGES dict mapping Fontsource subset names to CSS
  unicode-range descriptors for latin, latin-ext, cyrillic,
  cyrillic-ext, greek, and vietnamese
- Add _unicode_range() lookup function with empty-string fallback
  for unknown subsets (omitting the descriptor = all codepoints)
- Support "subsets" (list) config key alongside legacy "subset" (str)
  in _on_builder_inited — iterates all subsets in the download loop
- Emit unicode-range in font_faces dict; template renders it in
  @font-face blocks so browsers only download subset files when
  characters from that range appear on the page (zero cost for pages
  that only use ASCII)
- Preload uses the first (primary) subset only — typically "latin"
- Update page.html template: conditional unicode-range line in
  @font-face blocks
- Add 8 tests: _unicode_range (4), multi-subset builder-inited (2),
  legacy subset backward compat (1), preload primary subset (1)
why: Accented characters (ñ, ř, ž, ö) in contributor names, docstrings,
and code comments fell back to system fonts. latin-ext covers U+0100-02FF
and extended Latin ranges used across European languages.

what:
- Change "subset": "latin" to "subsets": ["latin", "latin-ext"] for both
  IBM Plex Sans and IBM Plex Mono
- Total font files: 32 (2 fonts × 2 subsets × 4 weights × 2 styles)
- Zero performance cost for ASCII-only pages: unicode-range descriptors
  tell the browser to skip latin-ext downloads when no extended chars
  appear on the page
@tony tony marked this pull request as ready for review March 31, 2026 22:25
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.02%. Comparing base (e1d43b7) to head (4760f29).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1034   +/-   ##
=======================================
  Coverage   81.02%   81.02%           
=======================================
  Files          28       28           
  Lines        2630     2630           
  Branches      492      492           
=======================================
  Hits         2131     2131           
  Misses        368      368           
  Partials      131      131           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony tony merged commit 68b45b4 into master Mar 31, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant