Skip to content

Commit 974eba9

Browse files
authored
Merge pull request #9977 from quarto-dev/bugfix/5413
Jupyter - trim whitespace and newlines from captions
2 parents 51736db + 9aa564f commit 974eba9

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

news/changelog-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ All changes included in 1.5:
104104
- ([#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.
105105
- ([#9536](https://github.com/quarto-dev/quarto-cli/issues/9536)): Provide traceback when available in Jupyter error outputs.
106106
- ([#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.
107+
- ([#5413](https://github.com/quarto-dev/quarto-cli/issues/5413)): Fix issue with Jupyter engine cells and images with captions containing newlines.
107108

108109
## Website Listings
109110

src/core/jupyter/jupyter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,12 @@ async function mdFromCodeCell(
13261326
}
13271327

13281328
// resolve caption (main vs. sub)
1329-
const { cellCaption, outputCaptions } = resolveCaptions(cell);
1329+
let { cellCaption, outputCaptions } = resolveCaptions(cell);
1330+
1331+
// https://github.com/quarto-dev/quarto-cli/issues/5413
1332+
outputCaptions = outputCaptions.map((caption) =>
1333+
caption.trim().replaceAll("\n", " ")
1334+
);
13301335

13311336
// cell_type classes
13321337
divMd.push(`.cell `);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: issue-5413
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ["figcaption.quarto-float-fig"]
8+
- []
9+
---
10+
11+
```{python}
12+
#| label: fig-1
13+
#| fig-cap: |
14+
#| This is a caption for my figure.
15+
#| It is long, so I put it onto two lines
16+
import numpy as np
17+
import matplotlib.pyplot as plt
18+
plt.plot(np.arange(10))
19+
```
20+
21+
See @fig-1.

0 commit comments

Comments
 (0)