Custom CSS that inverts the colors of images when a dark theme is toggled.
Project description
Sphinx-Image-Inverter
Sphinx extension that inverts the colors of images in dark mode, unless they are marked with the dark-light
class.
Introduction
When toggling dark mode in JupyterBook, images and figures are inverted by default. However, this inversion might not always be desired, as certain images may not look correct when their colors are flipped. The Sphinx-Image-Inverter extension provides a solution by allowing selective inversion control using the dark-light
class.
Installation
To install the Sphinx-Image-Inverter, follow these steps:
Step 1: Install the Package
Install the sphinx-image-inverter
package using pip
:
pip install sphinx-image-inverter
Step 2: Add to requirements.txt
Make sure that the package is included in your project's requirements.txt
to track the dependency:
sphinx-image-inverter
Step 3: Enable in _config.yml
In your _config.yml
file, add the extension to the list of Sphinx extra extensions:
sphinx:
extra_extensions:
- sphinx_image_inverter
Usage
Disable Image/Figure Inversion
By default, when dark-mode is toggled in JupyterBook, all images and figures are inverted. To prevent certain images from being inverted, apply the dark-light
class. The steps for both Markdown and HTML formats are given below.
For Markdown Format
-
Locate the markdown file that contains the image or figure you want to exclude from inversion.
-
Add the
:class: dark-light
attribute to the figure directive.Example:
```{figure} example_folder/example_image.jpg :class: dark-light :width: 400```
For HTML Format
If your image or figure is defined using HTML, apply the dark-light
class directly to the tag.
<iframe
src="some_figure.html"
width="600"
height="300"
class="dark-light">
</iframe>
Done! Now your image will not be inverted when dark mode is toggled.
Display Text According to Theme
You may want to display different text depending on whether the dark mode or light mode is enabled. To do that, you can use the following classes:
- Light Mode only:
<span class="only-light">Text only visible in Light Mode.</span>
- Dark Mode only:
<span class="only-dark">Text only visible in Dark Mode.</span>
These classes make sure that your text is only visible in the specified modes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sphinx_image_inverter-1.0.1.tar.gz
.
File metadata
- Download URL: sphinx_image_inverter-1.0.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f3a047de154f791467b001d3a6016ccf844d938964e4bb1a9b034112199261b |
|
MD5 | b652c320f0f4678aa43c9bb54baf5e1a |
|
BLAKE2b-256 | 8018b1d3ba5976b5799b28ed014590b1c5239af6ccde204e600fa056c459cb89 |
File details
Details for the file sphinx_image_inverter-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: sphinx_image_inverter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 202ab14f38b5076bef807a5323594036636360b6b8cc344c7cea2864c3718b29 |
|
MD5 | 2b0c71916c564fd53ec904a1bf4cfa5e |
|
BLAKE2b-256 | c3805645628f9922a4b39afef12849ff39975211809dc99bae876eedf0f09664 |