Skip to main content

A Sphinx extension to integrate Viewer.js for image zooming into Sphinx documentation (designed for JupyterBook v1).

Project description

TeachBooks Zoomies

A simple Sphinx extension to integrate Viewer.js for image zooming in Jupyter Books and Sphinx documentation.

[!NOTE] This extension is based on the original jb-zoomies.

Features

  • Pinch & Zoom: Smooth, mobile-friendly zooming for all your images.
  • Theme Integrated: Automatically adapts to light and dark modes, using your theme's native colors.
  • Smart Captions: Automatically pulls captions from <figure> elements to display them in the viewer.
  • Best-Fit Logic: Intelligently scales images to fit your viewport (configurable).
  • Customizable Toolbar: Choose exactly which tools (zoom, rotate, reset) are available to your readers.

Installation

pip install teachbooks-zoomies

Usage

Jupyter Book

Add the extension to your _config.yml:

sphinx:
  extra_extensions:
    - teachbooks_zoomies

Sphinx

Add the extension to your conf.py:

extensions = [
    # ...
    'teachbooks_zoomies',
]

Configuration

TeachBooks Zoomies works out-of-the-box with PyData-based themes (like the Jupyter Book default), but you can fully customize it in your _config.yml (Jupyter Book) or conf.py (Sphinx).

Options

Option Default Description
zoomies_selector ".bd-article img, #pst-secondary-sidebar img" CSS selector for images that should be zoomable.
zoomies_best_fit 70 Initial zoom level as a % of the viewport (1-100).
zoomies_toolbar ["zoomIn", "zoomOut", "oneToOne", "reset"] Tools to show. Options: zoomIn, zoomOut, oneToOne, reset, prev, play, next, rotateLeft, rotateRight, flipHorizontal, flipVertical.
zoomies_bg_color_light "color-mix(in srgb, var(--pst-color-background) 95%, transparent)" Viewer background color in light mode.
zoomies_bg_color_dark "color-mix(in srgb, var(--pst-color-background) 95%, transparent)" Viewer background color in dark mode.
zoomies_caption_color_light "var(--pst-color-text-base)" Caption text color in light mode.
zoomies_caption_color_dark "var(--pst-color-text-base)" Caption text color in dark mode.
zoomies_cdn_css "https://unpkg.com/viewerjs/dist/viewer.min.css" URL for the Viewer.js CSS file.
zoomies_cdn_js "https://unpkg.com/viewerjs/dist/viewer.min.js" URL for the Viewer.js JS file.

Example _config.yml (Jupyter Book)

sphinx:
  config:
    zoomies_selector: ".bd-article img, #pst-secondary-sidebar img, .my-custom-image-class"
    zoomies_best_fit: 85
    zoomies_toolbar: ["zoomIn", "zoomOut", "reset", "rotateRight"]

Example conf.py (Sphinx)

zoomies_selector = ".bd-article img, #pst-secondary-sidebar img"
zoomies_best_fit = 80

Disabling Zoom for Specific Images

If you want to prevent specific images from being zoomable, you can add the class no-zoomies to the image itself or to any of its parent containers.

1. In Markdown (MyST Directive)

This is the recommended way for Jupyter Books.

```{image} path/to/image.png
:class: no-zoomies
```

2. Using an HTML Tag

If you are writing raw HTML in your documentation.

<img src="path/to/image.png" class="no-zoomies">

3. Using a Parent Container

Useful for disabling zoom on a group of images at once.

<div class="no-zoomies">
  ![This image won't zoom](image1.png)
  ![This one won't either](image2.png)
</div>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teachbooks_zoomies-0.2.4.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teachbooks_zoomies-0.2.4-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file teachbooks_zoomies-0.2.4.tar.gz.

File metadata

  • Download URL: teachbooks_zoomies-0.2.4.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for teachbooks_zoomies-0.2.4.tar.gz
Algorithm Hash digest
SHA256 0d886cace2582838d899131a5cc5f57dda5077f4d535169ae5b93694f1f6cd2c
MD5 1056c0a583b91ce3770d0f5693908195
BLAKE2b-256 04be079d66d90fe3c4d446f1a6065464203f23cc3ec7d093ff6ed9ed9166ccc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for teachbooks_zoomies-0.2.4.tar.gz:

Publisher: python-publish.yml on TeachBooks/TeachBooks-Zoomies

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file teachbooks_zoomies-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for teachbooks_zoomies-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 254a69e3352b9466c067a72b089cd3e5038ee62d5b1c62ff7666635cd978779e
MD5 5ef1fdb88947dd7088c42f1668ee2a7e
BLAKE2b-256 2474f356db22f82eba6fd559128ae31222564f1e9e1e8b46a6ff93262621a9a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for teachbooks_zoomies-0.2.4-py3-none-any.whl:

Publisher: python-publish.yml on TeachBooks/TeachBooks-Zoomies

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page