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

ipynb - check if svg display data is encoded or not #9795

Merged
merged 4 commits into from
May 30, 2024
Merged

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented May 29, 2024

fixes #9793

We assumed svg mime type data was never encoded.

However, this is not the case when the Notebook file is produced by a pandoc convert --to ipynb. In this case, Pandoc will base64 encode the svg file. The svg data needs to be decoded before being written to the file at embedding time.Welcome to the quarto GitHub repo!

For Quarto, this will mostly happens in render context when embed is used as we generate this type of ipynb document internally.
It could also happens if a Python code in cell would also output a display_data with svg mime type and encoded data. It does not seem to be the common usage.

This is quite a narrow fix I believe, and as mentioned in #9793 , this is doing the same kind of check that we do in another function

// base 64 decode if its not svg
if (!imageText.trimStart().startsWith("<svg")) {
const imageData = base64decode(imageText);
Deno.writeFileSync(outputFile, imageData);
} else {
Deno.writeTextFileSync(outputFile, imageText);
}

cc @cwickham if you want to try on your side, though I added your example as a test

cderv added 4 commits May 29, 2024 12:16
We assumed svg mime type data was never encoded, but this is not the case when the SVG is produced by a pandoc convert `--to ipynb`. It happens in render context when embed is used. The svg data needs to be decoded before being written to the file at embedding time.
It seems Jupyter can output as svg mimetime a whole html document.
@cderv cderv merged commit 1c9cef7 into main May 30, 2024
49 checks passed
@cderv cderv deleted the fix/ipynb/encoded-svg branch May 30, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

embed svg plots are wrongly importly
2 participants