Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we fix images for darkmode? #39

Open
graeme-a-stewart opened this issue Nov 12, 2023 · 4 comments
Open

Can we fix images for darkmode? #39

graeme-a-stewart opened this issue Nov 12, 2023 · 4 comments
Labels
question Further information is requested

Comments

@graeme-a-stewart
Copy link
Member

The tutorial looks pretty bad in dark mode as the images have white backgrounds.

image

Just adding an alpha channel isn't going to work as the images have black in them, which will become invisible.

I don't know if this easily fixable though as the Jupyterbook website has the same issues. There doesn't seem to be an easy option to force light mode.

@graeme-a-stewart graeme-a-stewart added the question Further information is requested label Nov 12, 2023
@Moelf
Copy link
Member

Moelf commented Nov 12, 2023

@aoanla
Copy link
Collaborator

aoanla commented Nov 13, 2023

it must support theming by inspection, since looking at the actual HTML source reveals lines like:

<img src="_static/juliaheplogo.png" class="logo__image only-light" alt="Logo image"/>
<script>document.write(`<img src="_static/juliaheplogo.png" class="logo__image only-dark" alt="Logo image"/>`);</script>

so clearly some part of the Sphynx engine behind the scenes knows about the only-light and only-dark css classes...

@aoanla
Copy link
Collaborator

aoanla commented Nov 13, 2023

https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/branding.html is the Sphinx level documentation on this: I'll read it properly in the morning

@cormullion
Copy link

cormullion commented May 28, 2024

For the Documenter sidebar:

There are two main ways you can do this.

One is to make two versions of the logo, one for dark mode (logo_dark.svg|png), one for light mode (logo.svg|png). Documenter will switch between them:

Screenshot 2024-05-28 at 08 57 17 Screenshot 2024-05-28 at 08 55 46

The other way, if you "own" the logo, is to "own" the background as well, ie don't use transparent areas, bring your own background:

Screenshot 2024-05-28 at 09 13 48 Screenshot 2024-05-28 at 09 12 53

This makes life a bit simpler.

In the Documenter content area

Perhaps you don't own the logos, and can't add backgrounds -- you might have to switch between two versions of a logo.
But Documenter doesn't have built-in syntax for the content area, so you'll have to use CSS. Add a file eg extras.css to docs/src/assets/:

.display-light-only {
    display: block;
}

.display-dark-only {
    display: none;
}

.theme--documenter-dark .display-light-only {
    display: none;
}

.theme--documenter-dark .display-dark-only {
    display: block;
}

and include this CSS file into your make.jl file:

format   = Documenter.HTML(
      ...
        assets=["assets/extras.css"],
      ...
        ),

Then you can refer to different images for light and dark modes using the @raw form in your Markdown:

     ```@raw html
          <img class="display-light-only" src="assets/hsf_logo_blue.png" alt="hsf logo"/>
          <img class="display-dark-only" src="assets/hsf_logo_blue_darkbg.png" alt="hsf logo dark mode"/>
     ```
Screenshot 2024-05-28 at 09 20 16 Screenshot 2024-05-28 at 09 19 56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants