8000 Support dark mode toggle for SVGs and highlight.js by niklasl · Pull Request #4925 · speced/respec · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support dark mode toggle for SVGs and highlight.js #4925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

niklasl
Copy link
@niklasl niklasl commented Apr 1, 2025

Syntax highlighting already works with automatic preferences, but has not played well with neither default (no dark mode) settings, nor worked with the manual scheme toggle. (See also #4871.)

This fixes that using CSS (so that default behavior works without JS).

SVG behavior is by default based on user-agent preferences, and has therefore also not played well with the manual toggle. With this change, that is now handled by setting color-scheme: light or dark on the body element, based on the sidebar-provided manual scheme toggle.

If no meta element indicating dark color-scheme support is present, light mode is set on the body. This instructs SVGs to render in light mode when embedded in documents with no dark mode support, even when the user agent indicates dark mode. (The color-scheme CSS property can of course still be set to other values for various sections in a document, if so desired.)

A darkmode example document is also added, containing syntax-highlighted code and embedding an SVG document supporting light/dark color-scheme preferences.

Syntax highlighting already works with automatic preferences, but has
not played well with neither default (no dark mode) settings, nor worked
with the manual scheme toggle. (See also speced#4871.)

This fixes that using CSS (so that default behavior works without JS).

SVG behavior is by default based on user-agent preferences, and has
therefore also not played well with the manual toggle. With this change,
that is now handled by setting `color-scheme: light` or `dark` on the
body element, based on the sidebar-provided manual scheme toggle.

If no meta element indicating dark color-scheme support is present,
light mode is set on the body. This instructs SVGs to render in light
mode when embedded in documents with no dark mode support, even when the
user agent indicates dark mode. (The `color-scheme` CSS property can of
course still be set to other values for various sections in a document,
if so desired.)

A darkmode example document is also added, containing syntax-highlighted
code and embedding an SVG document supporting light/dark color-scheme
preferences.
@niklasl
Copy link
Author
niklasl commented May 22, 2025

Is there anything I can to to help out with this?

8000

@sidvishnoi
Copy link
Member
sidvishnoi commented May 26, 2025

Sorry for the delay in review. I've some concerns:

  • :has is a relatively new selector (although supported since 2023-ish), and for the generated docs, we try to use well supported features
  • Relying on that selector seems bit brittle as there's no guarantee if that'll be changed.
  • The which scheme is being used (and toggle) work is something that should be done in tr-design repo (I saw your comment in relevant issues there)

I don't feel too comfortable with the approach here of :has selector on a input[type=checkbox].

Regardless, I'd suggest removing the examples/darkmode.html, and add examples/figure1-lightdark.svg to some existing example.


Updated branch so the Netlify PR preview works.

Copy link
netlify bot commented May 26, 2025

Deploy Preview for respec-pr ready!

Name Link
🔨 Latest commit 02660da
🔍 Latest deploy log https://app.netlify.com/projects/respec-pr/deploys/683478c440a6a70008b01fc8
😎 Deploy Preview https://deploy-preview-4925--respec-pr.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

2 participants
0