Skip to content

Fix print output inheriting screen theme colors - #3169

Open
giri256 wants to merge 2 commits into
rust-lang:mainfrom
giri256:fix/print-light-palette
Open

giri256 wants to merge 2 commits into
rust-lang:mainfrom
giri256:fix/print-light-palette

Conversation

@giri256

@giri256 giri256 commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #1934.

Summary

  • reset print-only content variables to mdBook's existing light palette
  • keep all selected screen themes unchanged
  • cover page, text, quotes, tables, keyboard keys, footnotes, and callouts through the shared variables

Verification

  • Chrome print-media computed-style matrix for ayu, coal, light, navy, rust, and no-JavaScript navy
  • navy screen-media negative control
  • cargo test -p mdbook-html --lib
  • cargo fmt --check
  • git diff --check

Signed-off-by: Giridhar <80974392+giri256@users.noreply.github.com>
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Jul 27, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

Instead of redefining the variables, would be simpler to find a way to reuse the light variables from variables.css.

@GuillaumeGomez GuillaumeGomez added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Sep 8, 2026
Instead of repeating the light palette in print.css, limit the dark themes to screen media and let the light theme apply as the fallback.

Signed-off-by: Giridhar <80974392+giri256@users.noreply.github.com>
@giri256

giri256 commented Oct 18, 2026

Copy link
Copy Markdown
Author

Good point, done in 29ef7f0. print.css no longer repeats the palette. In variables.css, the dark themes (ayu, coal, navy, rust, and the no-JS prefers-color-scheme: dark block) now only apply to @media screen, and the light block also matches :where(:root) as a zero-specificity fallback. When printing, no dark theme matches, so the light variables apply whatever theme is selected. On screen nothing changes.

Most of the diff is re-indentation (git diff -w is +8/-2). I checked it by building a book with default-theme = "coal": the screen stays coal and the printed PDF uses the light palette, same as before. cargo test passes.

One trade-off: a custom theme defined only through additional-css still applies when printing, because it isn't inside the screen blocks. The previous print.css override covered that case. I'm happy to go either way.

@rustbot

rustbot commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print page is inheriting some theme colors

3 participants