epub.css: add optional dark-mode (light-dark) support - #11791
epub.css: add optional dark-mode (light-dark) support#11791k6G52m4Dz75W wants to merge 2 commits into
Conversation
The default EPUB stylesheet hardcodes a single dark text color (#1a1a1a) on top of the reading system's own background. This wraps that color — and the <hr> rule and table borders that use it — with CSS light-dark(), so readers supporting `color-scheme` get an inverted dark theme. Each light-dark() declaration is preceded by a plain #1a1a1a fallback, so readers that do not support light-dark() simply drop the new declaration and keep the unchanged original appearance (graceful degradation). No change to pandoc's conversion logic.
|
What if instead we simply removed the hard-coded dark color? |
|
You're right that, as a converter, a default stylesheet should stay neutral. Hard-coding a color means we're fighting the reading system, and for a generic default that's the wrong job. I'm happy to go either of two ways — I'll lay both out and let you pick. Route A — drop the hard-coded colors entirelyThis is the cleaner take on your suggestion. The five html {
line-height: 1.2;
font-family: Georgia, serif;
/* color removed: inherits the reading system's text color */
}
hr {
background-color: currentColor;
border: none;
height: 1px;
margin: 1em 0;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid;
border-bottom: 1px solid;
}
th {
border-top: 1px solid;
}
One piece I'd still keep from the patch, and it matters independently of :root {
color-scheme: light dark;
}Once Trade-off: Route B — keep
|
|
Route B is basically the patch in this PR, right? |
Yes — the current patch is Route B. It keeps
The only Color Level 5 piece is the
So the practical downside of the Color L5 dependency is small.
No — that's the key reassurance. On an older reader the Context — the two open dark-highlighting efforts. This is separate from the Suggestion: align the dark values with Breeze. The dark values aren't a I've pushed a revision aligning the document's dark values with the breezedark |
Add light/dark color scheme support to the default EPUB stylesheet
Summary
The default EPUB stylesheet (
data/epub.css) hardcodes asingle dark text color (
#1a1a1a) on top of the reading system's own (usuallywhite) background. This patch adds an optional dark-mode theme using the CSS
light-dark()function (CSS Color Module Level 5) without changing theappearance for readers that do not support it.
How it works
:root { color-scheme: light dark; }to enablelight-dark()and to letthe reading system flip its own canvas/scrollbars to dark.
#1a1a1a, used for body text, the<hr>rule, and table borders) withlight-dark(#1a1a1a, #e5e5e5), so thetheme cleanly inverts in dark mode (the dark value is the inverse of the light
value).
htmlbackground useslight-dark(transparent, #1a1a1a):transparentlets the reader's own background (white, sepia,paper, …) show through, so we never override a reader's preferred light theme.
#1a1a1a, slightly softer than pure black) isforced, so the book is actually dark even on readers that do not repaint their
canvas from
color-scheme.Backward compatibility (progressive enhancement)
Each
light-dark()declaration is preceded by a plain fallback using theoriginal
#1a1a1a(e.g.background-color: #1a1a1a;immediately beforebackground-color: light-dark(#1a1a1a, #e5e5e5);).A reader that does not understand
light-dark()treats the function as an invalidvalue and drops only that one declaration (it does not fall back to the first
argument). The preceding fallback therefore preserves the original look, so:
<hr>separator stays visible,#1a1a1a.No behavior change for legacy readers; the only difference is that modern readers
gain a dark theme.
Testing
Built an EPUB from a sample containing footnotes, blockquotes, code blocks,
<hr>,and tables; confirmed that
light-dark()and the#1a1a1afallbacks embedcorrectly in the generated
stylesheet1.css. (Actual dark/light rendering dependson the reading system's support for
color-scheme.)Scope
Stylesheet only — no change to pandoc's conversion logic.