repl: Render SVG cell outputs - #61718
Conversation
SVG outputs (image/svg+xml) previously fell through to "Unsupported media type". Render them through GPUI's SVG renderer, reusing the existing ImageView via a from_svg constructor, and rank SVG above raster images so a kernel that offers both shows the scalable version.
|
Thanks for this! Curious a bit, as #44512 proposed some more changes, were you aware of that PR and/or had a look? |
|
No, I hadn't seen #44512, thanks for the pointer. I looked through the open issues but not the closed PRs, so I missed it. The main blocker in that PR was that image/svg+xml was being parsed as a generic image and dropped, so it needed a cargo patch to jupyter_protocol. That looks fixed in the version Zed uses now (jupyter-protocol 1.4.0), so no patch is needed here. I tested it and SVG cells render fine. The other difference is I reused the existing ImageView through a from_svg constructor instead of adding a separate SVGView, to keep the change small. |
|
Adding onto that, I also saw another issue #60203 regarding the same was opened. |
|
@MrSubidubi thanks! I have pushed a fix to this branch. The CI failure was mine: the rank change for SVG broke two existing tests in outputs.rs (test_rank_mime_type_ordering and test_rank_mime_type_unsupported_returns_zero, which asserted that SVG ranks 0). Both are updated now. Also rebased on main, and repl tests, clippy and fmt pass locally. One thing worth a second opinion: I rank SVG above PNG, so a kernel that sends both shows the vector version. Happy to flip it if you would rather keep PNG first. Could you reopen this PR, or would you prefer I open a new one? |
|
@MrSubidubi no problem, opened a fresh one: #62889. Same branch and same commit, so the test fixes and the rebase are included. Thanks for taking the time to look at this one. |


Fixes #61717
SVG outputs from kernels (image/svg+xml) were showing "Unsupported media type" instead of the image. matplotlib, plotly, and other libraries commonly emit SVG, so this was a visible gap for data science users. This came up in discussion #25936.
This renders SVG outputs through GPUI's SVG renderer, reusing the existing ImageView with a from_svg constructor. It also ranks SVG above raster images so a kernel that provides both shows the scalable version.
I added a unit test that checks an SVG renders at its intrinsic size. This caught a scale factor bug where SVGs were rendering at twice their size. I also tested it locally on macOS and a cell producing image/svg+xml now renders the vector image inline.
Release Notes: