From e607284655af9752be3ac09f999bba9d9f821710 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 29 May 2024 12:16:25 +0200 Subject: [PATCH 1/4] ipynb - check if svg display data is encoded or not 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. --- src/core/jupyter/jupyter.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index 81ca3a2910..e11836bd6d 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1930,9 +1930,11 @@ function mdImageOutput( ? (data as string[]).join("") : data as string; - // base64 decode if it's not svg + // base64 decode if it's not encoded svg + // when used in embed context, Pandoc will generate ipynb with base64 encoded svg data + // https://github.com/quarto-dev/quarto-cli/issues/9793 const outputFile = join(options.assets.base_dir, imageFile); - if (mimeType !== kImageSvg) { + if (mimeType !== kImageSvg || !imageText.trimStart().startsWith(" Date: Wed, 29 May 2024 12:25:58 +0200 Subject: [PATCH 2/4] Add a test for the embed case --- tests/docs/smoke-all/2024/05/29/9713/main.qmd | 8 ++++++++ tests/docs/smoke-all/2024/05/29/9713/plots.qmd | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/docs/smoke-all/2024/05/29/9713/main.qmd create mode 100644 tests/docs/smoke-all/2024/05/29/9713/plots.qmd diff --git a/tests/docs/smoke-all/2024/05/29/9713/main.qmd b/tests/docs/smoke-all/2024/05/29/9713/main.qmd new file mode 100644 index 0000000000..3f9018787c --- /dev/null +++ b/tests/docs/smoke-all/2024/05/29/9713/main.qmd @@ -0,0 +1,8 @@ +--- +format: typst +_quarto: + tests: + typst: null +--- + +{{< embed plots.qmd#plot >}} diff --git a/tests/docs/smoke-all/2024/05/29/9713/plots.qmd b/tests/docs/smoke-all/2024/05/29/9713/plots.qmd new file mode 100644 index 0000000000..aedb3d45e6 --- /dev/null +++ b/tests/docs/smoke-all/2024/05/29/9713/plots.qmd @@ -0,0 +1,10 @@ +--- +title: "Plots" +fig-format: svg +--- + +```{r} +#| label: plot +plot(1:10) +``` + From 83d0bd7a1da118bb35140ca85d5426538841f63e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 29 May 2024 12:35:13 +0200 Subject: [PATCH 3/4] Add to changelog --- news/changelog-1.5.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.5.md b/news/changelog-1.5.md index fb045b9eb0..83e83da8d1 100644 --- a/news/changelog-1.5.md +++ b/news/changelog-1.5.md @@ -123,6 +123,7 @@ All changes included in 1.5: - ([#9635](https://github.com/quarto-dev/quarto-cli/issues/9635)): Respect `{shortcodes=false}` when resolving `include` shortcodes. - ([#9664](https://github.com/quarto-dev/quarto-cli/pull/9664)): Add `placeholder` shortcode to produce placeholder images. - ([#9665](https://github.com/quarto-dev/quarto-cli/issues/9665)): Fix issue with key-value arguments of shortcode handlers in code contexts. +- ([#9793](https://github.com/quarto-dev/quarto-cli/issues/9793)): `embed` shortcode now correctly retrieve svg image from embdedded cell. ## Lightbox Images From ab0d4d2b1cbf8954b251ed418ae8fcb2ef36f0c8 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 29 May 2024 14:05:58 +0200 Subject: [PATCH 4/4] Don't test only for svg at the start It seems Jupyter can output as svg mimetime a whole html document. --- src/core/jupyter/jupyter.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index e11836bd6d..3519f7dee9 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1930,11 +1930,15 @@ function mdImageOutput( ? (data as string[]).join("") : data as string; - // base64 decode if it's not encoded svg - // when used in embed context, Pandoc will generate ipynb with base64 encoded svg data - // https://github.com/quarto-dev/quarto-cli/issues/9793 const outputFile = join(options.assets.base_dir, imageFile); - if (mimeType !== kImageSvg || !imageText.trimStart().startsWith("