diff --git a/news/changelog-1.5.md b/news/changelog-1.5.md index e78f23372c3..2c7fe283fb1 100644 --- a/news/changelog-1.5.md +++ b/news/changelog-1.5.md @@ -103,6 +103,7 @@ All changes included in 1.5: - ([#9422](https://github.com/quarto-dev/quarto-cli/issues/9422)): Improve the stream merging algorithm in output cells to avoid merging outputs that should not be merged. - ([#9536](https://github.com/quarto-dev/quarto-cli/issues/9536)): Provide traceback when available in Jupyter error outputs. - ([#9470](https://github.com/quarto-dev/quarto-cli/issues/9470)): Fix images rendered by the Jupyter engine to be displayed with the same dimensions as those in notebooks. +- ([#5413](https://github.com/quarto-dev/quarto-cli/issues/5413)): Fix issue with Jupyter engine cells and images with captions containing newlines. ## Website Listings diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index 3519f7dee9a..ee86aaa4457 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1326,7 +1326,12 @@ async function mdFromCodeCell( } // resolve caption (main vs. sub) - const { cellCaption, outputCaptions } = resolveCaptions(cell); + let { cellCaption, outputCaptions } = resolveCaptions(cell); + + // https://github.com/quarto-dev/quarto-cli/issues/5413 + outputCaptions = outputCaptions.map((caption) => + caption.trim().replaceAll("\n", " ") + ); // cell_type classes divMd.push(`.cell `); diff --git a/tests/docs/smoke-all/2024/06/12/5413.qmd b/tests/docs/smoke-all/2024/06/12/5413.qmd new file mode 100644 index 00000000000..7d15e2589d9 --- /dev/null +++ b/tests/docs/smoke-all/2024/06/12/5413.qmd @@ -0,0 +1,21 @@ +--- +title: issue-5413 +_quarto: + tests: + html: + ensureHtmlElements: + - ["figcaption.quarto-float-fig"] + - [] +--- + +```{python} +#| label: fig-1 +#| fig-cap: | +#| This is a caption for my figure. +#| It is long, so I put it onto two lines +import numpy as np +import matplotlib.pyplot as plt +plt.plot(np.arange(10)) +``` + +See @fig-1. \ No newline at end of file