Make firefox-source-docs support dark mode
Categories
(Developer Infrastructure :: Source Documentation, enhancement)
Tracking
(firefox158 fixed)
| 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.svgfiles paint#20123awherevercontext-fillis unavailable, which is any web embed, so the wordmark is near-black on a dark surface. Puttinglight-dark()in the fallback fixes it, andcontext-fillstill 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_themeto the light theme because the page could not follow. That pin comes out, and theclassDef/styledeclarations that hardcode a lightfillwithout acolorget an explicit label colour.
| Assignee | ||
Updated•2 months ago
|
| Assignee | ||
Comment 1•2 months ago
|
||
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.
| Assignee | ||
Comment 2•2 months ago
|
||
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.
| Assignee | ||
Comment 3•2 months ago
|
||
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.
Comment 5•2 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/f7272db47dbc
https://hg.mozilla.org/mozilla-central/rev/ad8a35458ea4
https://hg.mozilla.org/mozilla-central/rev/9bf5714c3f85
Description
•