ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
69 stars 38 forks source link

Feature (html): Enable light-dark color scheme using `prefers-color-scheme` #728

Open broofa opened 2 years ago

broofa commented 2 years ago

Working on the new UUID spec in the early morning, I find myself getting a bit blinded as I switch back and forth between the spec, github, and my terminal. See below.

It'd be nice if the HTML generated by this tool took advantage of prefers-color-scheme to present an appropriately light/dark theme to the user.

CleanShot 2022-02-19 at 04 12 26

pusateri commented 1 year ago

For the internet drafts where HTML is generated from XML, it would be great if the template would include dark-mode. This would require a header that advertises the document supports both light and dark as well as some tweaking of the color and background-color CSS so that these colors don't override the colors in dark-mode. As an experiment, I added

:root {
    color-scheme: light dark;
}

And then commented out all of the color and background-color attributes and the draft did properly switch to dark mode. The problem is that in order the keep the current color selections in light mode, a subsequent list of colors will need to be selected for dark mode too.

pusateri commented 1 year ago

This looks like a good approach to follow: https://medium.com/gumgum-tech/light-vs-dark-mode-debate-prefers-color-scheme-will-answer-d079a5f106aa

:root {
        color-scheme: light dark;
    --background-color: #ffffff; /* white background */
}

@media (prefers-color-scheme: light) {
    :root {
            --background-color: #ffffff; /* white background */
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #000000; /* black background */
    }
}