Add dark mode support to the HTML versions of the OpenAPI specs
Update the rendering process for the HTML versions of the OpenAPI specs (using ReSpec) to generate pages that support dark mode.
ReSpec has added dark mode support: https://github.com/speced/respec/issues/2651
Related: #3576
Paging @Bellangelo (we're working on making it so that we can assign issues to you, but haven't quite sorted that out yet).
Unfortunately, this seems not to be so easy. Our js/respec-oai.js file loads this css file https://www.w3.org/StyleSheets/TR/2016/base.css which overrides most styles. There is a https://www.w3.org.org/StyleSheets/TR/2026/dark.css but even if we add it, it still gets overridden by the base.css.
It looks like we need to give more effort in this issue https://github.com/OAI/OpenAPI-Specification/issues/3845 which will help us have more control over the respec-oai.js
ReSpec documentation of dark mode says
Note: This is supported for W3C specs only, and makes use of official dark.css in tr-design.
We can enable the switch, and it has no effect 😞
@mikekistler Don't know what changed in the last two weeks, now dark mode seems to work (at least if your system theme is set to dark mode):
- https://ralfhandl.github.io/OpenAPI-Specification/oas/latest-dark.html
Quite some fine-tuning needed for dark mode to really work:
- different OAS logos for light/dark mode
- table and code-block background color depending on light/dark mode
- ...
I'll gladly leave this to someone fluent in CSS 😁
I have started on this, please assign to my name.
Intermediate results can be seen here: https://pavelkornev.github.io/OpenAPI-Specification/oas/latest.html
Hi @pavelkornev, I used some of your CSS in this PR to continue on this work. If you have already a PR that I missed then I can close mine and use yours instead.
Hi @pavelkornev, I used some of your CSS in this PR to continue on this work. If you have already a PR that I missed then I can close mine and use yours instead.
The approach i tried won't work because then switcher between Dark/Light mode doesn't work properly. Try both scenarious:
- System settings set to Light mode: try switch between Dark/Light using switcher
- System settings set to Dark mode: try switch between Dark/Light using switcher
Hi @pavelkornev, I used some of your CSS in this PR to continue on this work. If you have already a PR that I missed then I can close mine and use yours instead.
The approach i tried won't work because then switcher between Dark/Light mode doesn't work properly. Try both scenarious:
- System settings set to Light mode: try switch between Dark/Light using switcher
- System settings set to Dark mode: try switch between Dark/Light using switcher
Thanks a lot @pavelkornev for your feedback ❤ . I had encapsulated the styling under the preferred-color-scheme. It should be fixed now. See https://github.com/OAI/OpenAPI-Specification/pull/4268/commits/973999a6a7c1e774b72ca44aa24cf53d4647f782