quarto-dev / quarto-dev/quarto-cli

Multi-line alternative text doesn't work for python cells

Open
#10,216 2 comments 0 reactions 1 assignee View on GitHub

@cscheid is already working on this.

Since Jul 3, 2024.

bug engines-jupyter
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Quarto version 1.5.52.

The two cells in the following document should produce the same output, but they don't. I've used echo: fenced to show the result clearly.

---
format: html
execute: 
  echo: fenced
---

```{python}
#| label: import-pkgs
import numpy as np
import matplotlib.pyplot as plt
```

```{python}
#| label: fig-single-line-alt
#| fig-alt: Looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg alternative text string that would be better as a multi-line entry.
#| fig-cap: Figure caption
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
  subplot_kw = {'projection': 'polar'} 
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```

```{python}
#| label: fig-multi-line-alt
#| fig-alt: |
#|   Looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg alternative 
#|   text string that would be better as a multi-line entry
#| fig-cap: Figure caption
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
  subplot_kw = {'projection': 'polar'} 
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```

See the result below.

Screenshot 2024-07-03 at 3 08 38 PM

The issues are:

  1. Alt text not processed properly for the multi-line case.
  2. Figure caption also not processed properly even though nothing changed in how it's defined.
  3. Figure sizes are different (though this might partially be due to no caption/figure environment).

Multi-line alt text works in R, see below.

Screenshot 2024-07-03 at 3 11 22 PM

Code from the above image included below for reproducibility.

---
format: html
---

```{r}
#| label: fig-single-line-alt
#| fig-alt: Looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg alternative text string that would be better as a multi-line entry.
#| fig-cap: Figure caption
plot(cars)
```

```{r}
#| label: fig-multi-line-alt
#| fig-alt: |
#|   Looooooooooooooooooooonnnngggg looooooooooooooooooooonnnngggg 
#|   looooooooooooooooooooonnnngggg alternative 
#|   text string that would be better as a multi-line entry.
#| fig-cap: Figure caption
plot(cars)
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.