Skip to content

Conversation

@gordonwoodhull
Copy link
Contributor

@gordonwoodhull gordonwoodhull commented Feb 27, 2025

fixes #1325

Introduces a new script before the body which runs immediately, enabling or disabling dark mode.

Also, both light and dark stylesheets are loaded at once, and then one immediately disabled, instead of dark starting as rel="prefetch", which was one of the causes of flashing.

Submitting as a draft for three reasons:

  1. It's a pretty big change to the structure of the HTML, would appreciate folks giving it a look-over and/or testing.
  2. It does not degrade nicely when JavaScript is disabled - want to investigate if there is an alternative that does load the dark stylesheet eagerly but disables it. 1
  3. I'm out next week and don't want to check in this big a change before I go.

Footnotes

  1. Worst case, it does work to load the light stylesheet after the dark stylesheet, with a few fixes to the JS that currently depend on stylesheet order.

@gordonwoodhull gordonwoodhull added this to the v1.7 milestone Feb 27, 2025
@gordonwoodhull gordonwoodhull force-pushed the bugfix/1325 branch 2 times, most recently from aff3fec to 7e06952 Compare March 13, 2025 14:30
@gordonwoodhull
Copy link
Contributor Author

gordonwoodhull commented Mar 13, 2025

I could not find any solution for NoJS except reversing the order of stylesheets, so I'm going with that solution.

It may cause style bleed if the light stylesheet does not replace everything, but only for NoJS folks. Seems like the least bad compromise.

  • Only reverse if light theme is default
  • Clean up dead code that was disabling one of the stylesheets
  • Also conditionally reverse syntax highlighting stylesheets

To be merged after #12277 to share tests.

@gordonwoodhull gordonwoodhull marked this pull request as ready for review March 13, 2025 14:38
@gordonwoodhull gordonwoodhull marked this pull request as draft March 13, 2025 15:24
@gordonwoodhull gordonwoodhull marked this pull request as ready for review March 14, 2025 03:53
a filter to detect e.g. renderings: [light, dark]

retain any cell content before the first cell-output-display
then any div.cell-output-display are given the rendering names

formats choose what to do with these in the filter
currently HTML uses light and dark and classes them .light-content and .dark-content
and the other formats just use light rendering

applies body.quarto-light or body.quarto-dark based on default theme
for a decent NoJS experience
fixes #1325

introduces a new script before the body
which runs immediately, enabling or disabling dark mode

both stylesheets are loaded, one is disabled in JS

the default stylesheet is loaded second, in case JS is disabled
@gordonwoodhull gordonwoodhull merged commit a496e0e into main Mar 14, 2025
49 checks passed
@gordonwoodhull gordonwoodhull deleted the bugfix/1325 branch March 14, 2025 06:39
gordonwoodhull added a commit that referenced this pull request Mar 24, 2025
for #12319 and (to a lesser degree) #12173
testing theme/brand integration and dark brand
gordonwoodhull added a commit that referenced this pull request Mar 24, 2025
for #12319

testing theme/brand integration and dark brand

also includes NoJS tests for #12173
gordonwoodhull added a commit that referenced this pull request Mar 24, 2025
for #12319

testing theme/brand integration and dark brand

also includes NoJS tests for #12173
cderv added a commit that referenced this pull request Apr 17, 2025
This rever "Merge pull request #11047 from kv9898/main"

reverting commit 61f987c, reversing
changes made to dca5984.

Updated logic for handling Light / Dark mode is now enough to load
the correct theme at startup. So #12173 fix the initial issue #8613
cderv added a commit that referenced this pull request Apr 17, 2025
This reverts "Merge pull request #11047 from kv9898/main"

reverting commit 61f987c, reversing
changes made to dca5984.

Updated logic for handling Light / Dark mode is now enough to load
the correct theme at startup. So #12173 fix the initial issue #8613
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.

Flashing when switching between pages in dark theme.

2 participants