Closed Bug 2071163 Opened 2 months ago Closed 2 months ago

Make firefox-source-docs support dark mode

Categories

(Developer Infrastructure :: Source Documentation, enhancement)

enhancement

Tracking

(firefox158 fixed)

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: dao, Assigned: dao)

References

(Blocks 1 open bug)

Details

Attachments

(3 external files)

sphinx-rtd-theme has no dark mode, so firefox-source-docs stays light whatever the reader prefers. Upstream is not adding one: readthedocs/sphinx_rtd_theme#224 has been open since 2015 and the maintainers have it waiting on a Bootstrap rewrite. 3.1.0 is the current release and is what we pin.

The theme offers nothing to re-point either -- theme.css is built CSS carrying 237 colour literals over 74 distinct values, with no custom properties. So a new Sphinx extension, docs/_addons/dark_mode.py, reads the stylesheets the build has already written, maps each colour through OKLCh (lightness flips; a saturated accent keeps its hue and gets a lightness floor) and writes the result as a prefers-color-scheme: dark override, alongside a dark pygments sheet for code blocks. Deriving it at build time keeps it in step with a theme bump. The sidebar, mobile header and version flyout are already dark in the light theme and are left alone.

Two things ride along:

  • The branding firefox-wordmark.svg files paint #20123a wherever context-fill is unavailable, which is any web embed, so the wordmark is near-black on a dark surface. Putting light-dark() in the fallback fixes it, and context-fill still wins for the chrome consumers because the colour stays in the presentation attribute rather than moving to a CSS rule.
  • Bug 2070774 pinned mermaid_dark_theme to the light theme because the page could not follow. That pin comes out, and the classDef/style declarations that hardcode a light fill without a color get an explicit label colour.
Assignee: nobody → dao+bmo
Summary: Give firefox-source-docs a dark color scheme → Make firefox-source-docs support dark mode

The added rule only declares color-scheme, which is what makes light-dark() resolve; nothing competes with the context-fill in the presentation attribute, so the chrome consumers that supply one are unaffected. The fallback is what a web embed paints, since context paint is restricted to chrome://, resource:// and a short allowlist.

sphinx-rtd-theme has no dark mode and no custom properties to re-point, so the override is derived from the theme's own stylesheets at build time rather than checked in.

Bug 2070774 pinned both mermaid themes to the light one because the page could not follow. A classDef or style that hardcodes a fill keeps that color in either scheme, so those nodes need an explicit color too, or the dark theme's label color lands on a light fill at 1.4:1.

Pushed by dgottwald@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/0ab1a9f0dcd6 https://hg.mozilla.org/integration/autoland/rev/f7272db47dbc Give the branding wordmarks a dark-mode fill fallback. r=sylvestre https://github.com/mozilla-firefox/firefox/commit/63ce0ef60c58 https://hg.mozilla.org/integration/autoland/rev/ad8a35458ea4 Derive a dark color scheme for firefox-source-docs. r=firefox-source-docs-reviewers,sylvestre https://github.com/mozilla-firefox/firefox/commit/1074aebedd1c https://hg.mozilla.org/integration/autoland/rev/9bf5714c3f85 Let mermaid diagrams follow the page color scheme. r=firefox-source-docs-reviewers,sylvestre
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: