nbsphinx
nbsphinx copied to clipboard
Support dark mode
in your furo theme branch, you don’t style data frames in a way that’s readable on a dark background:
this is how this page looks for me by default https://nbsphinx.readthedocs.io/en/furo-theme/code-cells.html:

after:

I don’t know if other themes’ dark modes
Thanks for this PR!
I'm not yet familiar with dark mode, I'll have to read up a bit.
But I already have a question: How does JupyterLab (which also has a dark theme) handle this situation? In a similar way?
The general problem is that while many things are able to use the system theme by default (prefers-color-scheme: dark), they also allow some toggle to override this. And the way this manually selected state is stored depends on the theme / app author.
- jupyterlab has
<body data-jp-theme-light="false"> - The upcoming dark mode for the pydata theme (https://github.com/pydata/pydata-sphinx-theme/pull/540) has
<html data-theme="dark"> - Furo has
<body data-theme="dark">
Btw this PR will not work when user prefers dark, so it needs to do something like not theme="light"
see https://github.com/scverse/scvi-tools/pull/1448
Why not? You’re doing body:not([data-theme=light]) <selector> and I’m doing *[data-theme="dark"] <selector>. Both should work right?
not exactly, at least it didn't for me when your browser "prefers dark"
(not night mode on furo, but this is the "default", prefers logo)

I have also run into this, needed a solution quickly so I overrode the hardcoded colors in https://github.com/spatialaudio/nbsphinx/blob/master/src/nbsphinx.py#L658 with theme-agnostic CSS variables from Jupyter:
.jp-RenderedHTMLCommon table,
div.rendered_html table {
color: var(--jp-ui-font-color1) !important;
}
.jp-RenderedHTMLCommon thead,
div.rendered_html thead {
border-bottom: var(--jp-border-width) solid var(--jp-border-color1) !important;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(odd),
div.rendered_html tbody tr:nth-child(odd) {
background: var(--jp-layout-color0) !important;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(even),
div.rendered_html tbody tr:nth-child(even) {
background: var(--jp-rendermime-table-row-background) !important;
}
.jp-RenderedHTMLCommon tbody tr:hover,
div.rendered_html tbody tr:hover {
background: var(--jp-rendermime-table-row-hover-background) !important;
}
ETA Would it be easier to unbreak Furo dark mode by removing the explicit color values introduced in #228?
I think I have an approach that should work.
Could you take a look please?
By the way, stderr is also a bit hard to read:

Just to add some information about the dark-themes in general, in pydata-sphinx-theme we decided to endorse the support of the dark-theme display so we do customise the redenring of supported libs to match the theme color scheme.
https://github.com/pydata/pydata-sphinx-theme/tree/main/src/pydata_sphinx_theme/assets/styles/extensions
As it's very much theme related, I'm not sure that coloring should be a responsability of nbsphinx itself.