sphinx-gallery icon indicating copy to clipboard operation
sphinx-gallery copied to clipboard

Define CSS variables when `html[data-theme]` does not exist

Open glemaitre opened this issue 2 years ago • 6 comments

Currently in sphinx-gallery as set of CSS variables (e.g. sg-background-color) are defined to handle dark/light modes based on a CSS selector defined by pydata-sphinx-theme (i.e. data-theme=light/dark).

It makes that sphinx-gallery is coupled with pydata-sphinx-theme and the CSS variable will exist only if the <html> tag define the data-theme selector as show here:

https://github.com/scikit-learn/scikit-learn/pull/27659/files#diff-7dc66b1264ca920ea9fd1be8da9eb0d0c1250435d13b83cd69dd14c74e9de59bR12-R14

Somehow, these CSS variables are useful on our hand because it allows to detect the context where we draw the diagram (notebook, IDE, HTML page).

I was wondering if in the context of not using pydata-sphinx-theme, these CSS variables could still exist with a default light mode without the need to create the CSS selector from pydata-sphinx-theme, that could be quite tricky to debug when something goes wrong.

NB: I am far to be fluent with the HTML/CSS principles and stacks and I am open to any solution if it appears that we should do differently on sckit-learn side.

glemaitre avatar Nov 03 '23 18:11 glemaitre

just a note to say that this isn't especially unique to pydata-sphinx-theme. For example bootstrap uses the same approach to dynamically changing color theme, and calls it data-bs-theme=light/dark, and there are several other examples out there (one two three four) that use the same data-theme variable name that pydata-sphinx-theme does.

drammock avatar Nov 03 '23 20:11 drammock

@larsoner thoughts on this? CSS stuff goes over my head.

lucyleeow avatar Nov 09 '23 04:11 lucyleeow

Also I wonder if we (scikit-learn) should put efforts into converting to pydata theme, but I am not sure who is well versed in html and has the interest...

lucyleeow avatar Nov 09 '23 04:11 lucyleeow

Also I wonder if we (scikit-learn) should put efforts into converting to pydata theme,

We (scikit-learn) should. Chiara Marmo started this work. It is a substantial effort and we should probably create a feature branch from her work and iterate on it.

GaelVaroquaux avatar Nov 09 '23 07:11 GaelVaroquaux

Also I wonder if we (scikit-learn) should put efforts into converting to pydata theme,

Yes we should for sure. +1 with @GaelVaroquaux thoughts.

but I am not sure who is well versed in html and has the interest...

I would be interested to have the thing move forward. I assume that the theme should reduce the tricks that we are doing (or we should contribute upstream). I am also far to be know what I am doing with HTML/CSS but we can have a first good-looking enough version and one day, we might get feedbacks/help from UX + frontend developers.

glemaitre avatar Nov 09 '23 09:11 glemaitre

Yes, and maybe it is enough to have someone good with HTML/CSS to review the work.

lucyleeow avatar Nov 10 '23 02:11 lucyleeow