Skip to content

Using a reference with formulas inside of a figure caption, breaks the generated HTML #1473

Open
@leoschwarz

Description

@leoschwarz

Dear developers,
The second plot is rendered correctly whereas the first one is messed up unless you add a fig.alt since the unescaped HTML of the formula ends up in the aria-label tag of the <img> element.

---
title: "Circle Plot"
output:
  bookdown::html_document2:
    toc: yes
    toc_depth: 2
---

(ref:caption) The formula for a circle: $x^2 + y^2 = r^2$).

```{r circle-plot, fig.cap="(ref:caption)"}
t <- seq(0, 2*pi, length.out = 1000)
x <- cos(t)
y <- sin(t)

plot(x, y, type = "l", asp = 1, xlab = "x", ylab = "y", main = "Circle")
```

```{r circle-plot2, fig.cap="The formula for a circle: $x^2 + y^2 = r^2$."}
plot(x, y, type = "l", asp = 1, xlab = "x", ylab = "y", main = "Circle")
```
grafik

Checklist

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('bookdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • installed and tested your bug with the development version of the bookdown package using remotes::install_github("rstudio/bookdown") ?

R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin23.4.0
Running under: macOS Sonoma 14.5

Locale: de_CH / UTF-8 / de_CH / C / de_CH / de_CH

Package version:
  base64enc_0.1.3   bookdown_0.40.1   bslib_0.8.0       cachem_1.1.0
  cli_3.6.3         digest_0.6.36     evaluate_0.24.0   fastmap_1.2.0
  fontawesome_0.5.2 fs_1.6.4          glue_1.7.0        graphics_4.4.1
  grDevices_4.4.1   highr_0.11        htmltools_0.5.8.1 jquerylib_0.1.4
  jsonlite_1.8.8    knitr_1.48        lifecycle_1.0.4   memoise_2.0.1
  methods_4.4.1     mime_0.12         R6_2.5.1          rappdirs_0.3.3
  rlang_1.1.4       rmarkdown_2.27    sass_0.4.9        stats_4.4.1
  tinytex_0.52      tools_4.4.1       utils_4.4.1       xfun_0.46
  yaml_2.3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions