spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
449 stars 128 forks source link

make CSS agnostic of light/dark schemes #734

Open 2bndy5 opened 1 year ago

2bndy5 commented 1 year ago

I noticed a problem with the furo theme example: The background color for stderr output isn't compatible with the dark scheme: image but using a transparency with slightly increased saturation should remedy that in a consistent way for light or dark schemes:

/* nbsphinx-code-cells.css | https://nbsphinx.readthedocs.io/en/furo-theme/_static/nbsphinx-code-cells.css */

div.nboutput.container div.output_area.stderr {
  /* background: #fdd; */
  background: #e8808075;
}

image

There are other styles that use opaque hard-coded colors which don't blend well with light and dark schemes. I'll update this thread with other related findings...

2bndy5 commented 1 year ago

hardcoded colors that could be made agnostic of BG color:

The following is subject to #733: https://github.com/spatialaudio/nbsphinx/blob/a619a5091c29815c1605166d6adca26700fae6e9/src/nbsphinx/_static/nbsphinx-code-cells.css_t#L130

mgeier commented 1 year ago

Thanks for reporting this!

nbsphinx is not supporting dark themes yet (see also #635).

I would like to fix this at some point, but I'm still too confused about how to do that. Sphinx has hardly any support for a dark theme, and many third party themes use quite different technologies for their dark themes. I think this makes it basically impossible to be working correctly on all themes.

The idea with transparency sounds nice, but I guess it can only be used in a few situation and not as a general strategy, right?

For comparison, this is how the JupyterLab dark theme looks like:

image

2bndy5 commented 1 year ago

Sphinx has hardly any support for a dark theme

I don't think dark mode is a Sphinx support issue. It can be done with HTML and CSS templates.

many third party themes use quite different technologies for their dark themes

Sort of. From what I've seen, light/dark modes are typically toggled using an attribute on the DOM <body>. The only thing that is really inconsistent is the name of the attribute that is used.

CSS has a media feature that can be used to compensate for these scenarios, but it might not fit all themes.

The idea with transparency sounds nice, but I guess it can only be used in a few situation and not as a general strategy, right?

If you absolutely want the color to be opaque, then it is harder to satisfy this. But I would recommend the aforementioned CSS media feature when transparency isn't preferrable.

Changing the foreground color makes sense, but it should really only be done if changing the background color to something opaque (as is done for certain rows of tables in nbsphinx).