quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.57k stars 294 forks source link

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

Open mine-cetinkaya-rundel opened 5 days ago

mine-cetinkaya-rundel commented 5 days ago

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
#| 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()
#| 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.

<img width="276" alt="Screenshot 2024-07-03 at 3 08 38 PM" src="https://github.com/quarto-dev/quarto-cli/assets/5965649/3d8e387e-07f2-48c7-ab4a-75bf5ef1645d">

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.

<img width="1153" alt="Screenshot 2024-07-03 at 3 11 22 PM" src="https://github.com/quarto-dev/quarto-cli/assets/5965649/4f195ba2-78f1-4b5b-837c-b147372a1a60">

Code from the above image included below for reproducibility.

````markdown
---
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)
#| 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)
cscheid commented 4 days ago

Thanks. We've fixed captions in 1.5, but we need to do this for all attributes that will end up in the div.

mcanouil commented 4 days ago

For reference:

And somewhat related: