Skip to content

Apply classes from the image output metadata - #731

Merged
bsipocz merged 1 commit into
executablebooks:mainfrom
headtr1ck:output-metadata-image-classes
Oct 19, 2026
Merged

bsipocz merged 1 commit into
executablebooks:mainfrom
headtr1ck:output-metadata-image-classes

Conversation

@headtr1ck

Copy link
Copy Markdown
Contributor

Image outputs can already set their width and height in the output metadata (#588), but classes are ignored. With this PR they are added to the classes from the cell metadata, so each image output of a cell can be styled separately.

  • The main use case is dark mode: a cell can display a figure twice, tagged with the theme's only-light / only-dark classes, e.g. display(fig, metadata={"image/png": {"classes": "only-dark"}}). We do this in the xarray docs (Show matplotlib figures in the docs with a dark mode version pydata/xarray#11758), which currently has to monkeypatch NbElementRenderer.render_image for it.
  • Classes are added to rather than replacing the cell classes, since they are usually specific to one output.
  • Adds a test case to metadata_image_output.ipynb and documents output metadata in "Images and Figures".

AI disclosure: written with the help of Claude Code, reviewed and tested by me.

🤖 Generated with Claude Code

Image outputs can already set their width and height in the output
metadata, but classes were ignored. Add them to the classes from the
cell metadata, so each image output of a cell can be styled separately,
e.g. with the only-light / only-dark classes of a theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@bsipocz bsipocz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable and as it fixes a downstream issue, let's go ahead with the merge.

Thanks!

@bsipocz
bsipocz merged commit 06e4880 into executablebooks:main Oct 19, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants