Skip to content

Commit 956665f

Browse files
fix: propagate fig-alt on static images to Typst image alt text
The Typst Image handler only checked the `alt` attribute, missing Quarto's `fig-alt` attribute on static (non-computed) images. This mirrors the existing fig-alt handling in quarto-post/html.lua. Closes #14108
1 parent ffa7d39 commit 956665f

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/resources/filters/quarto-post/typst.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ function render_typst_fixups()
227227

228228
-- Workaround for Pandoc not passing alt text to Typst image() calls
229229
-- See: https://github.com/jgm/pandoc/pull/11394
230-
local alt_text = image.attributes["alt"]
230+
-- Check fig-alt first (Quarto's custom alt text override), then alt, then caption
231+
local alt_text = image.attributes[kFigAlt] or image.attributes["alt"]
232+
if alt_text then
233+
image.attributes[kFigAlt] = nil
234+
end
231235
if (alt_text == nil or alt_text == "") and #image.caption > 0 then
232236
alt_text = pandoc.utils.stringify(image.caption)
233237
end
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "Typst fig-alt propagation for static images"
3+
format:
4+
typst:
5+
keep-typ: true
6+
_quarto:
7+
tests:
8+
typst:
9+
noErrors: default
10+
ensureTypstFileRegexMatches:
11+
- # Patterns that MUST be found - fig-alt propagated to image(alt: ...)
12+
- 'alt:\s*"Alt for captioned non-crossref image"'
13+
- 'alt:\s*"Alt for uncaptioned image"'
14+
- # Patterns that must NOT be found
15+
[]
16+
---
17+
18+
## Static image with caption but no cross-ref label
19+
20+
![A caption](typst-fig-alt-static-images-img.svg){fig-alt="Alt for captioned non-crossref image"}
21+
22+
## Static image without caption and no cross-ref label
23+
24+
![](typst-fig-alt-static-images-img.svg){fig-alt="Alt for uncaptioned image"}

0 commit comments

Comments
 (0)