Skip to content

Commit

Permalink
Merge pull request #9191 from quarto-dev/bugfix/9190
Browse files Browse the repository at this point in the history
lua - don't strip fig-alt from image when rendering html figure
  • Loading branch information
cscheid committed Mar 25, 2024
2 parents 86248b4 + 0b7ed68 commit 9585cf8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: "Alt text"
format:
html:
quality: 2
revealjs:
quality: 2
_quarto:
tests:
html: &html_like_tests
ensureHtmlElements:
- ['img#case1[alt="Alt"]',
'img#case2[alt="Alt"]',
'div#fig-case3 img[alt="Alt"]',
'div#fig-case4 img[alt="Alt"]',
'div#tbl-case5 img[alt="Alt"]',
'div#tbl-case6 img[alt="Alt"]']
- []
revealjs: *html_like_tests
---

## In HTML

With caption, becomes a pandoc.Figure, but not a float:

![Caption](https://placeholder.co/400/400){#case1 fig-alt="Alt"}

Without caption, it's simply an image:

![](https://placeholder.co/400/400){#case2 fig-alt="Alt"}

In crossreferenceable figures, with and without captions:

![Caption](https://placeholder.co/400/400){#fig-case3 fig-alt="Alt"}

![](https://placeholder.co/400/400){#fig-case4 fig-alt="Alt"}

In crossreferenceable non-figure floats, with and without captions:

![Caption](https://placeholder.co/400/400){#tbl-case5 fig-alt="Alt"}

![](https://placeholder.co/400/400){#tbl-case6 fig-alt="Alt"}



6 changes: 3 additions & 3 deletions src/resources/filters/layout/html.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function renderHtmlFigure(el, render)
end
end

local keys = tkeys(el.attr.attributes)
for _,k in pairs(keys) do
if isFigAttribute(k) then
for _, k in pairs(tkeys(el.attr.attributes)) do
-- can't strip fig-alt here
if isFigAttribute(k) and k ~= kFigAlt then
el.attr.attributes[k] = nil
end
end
Expand Down
11 changes: 11 additions & 0 deletions tests/docs/smoke-all/2024/03/25/9190.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: "Alt text"
_quarto:
tests:
html:
ensureHtmlElements:
- ['img[alt="Alt"]']
- []
---

![Caption](https://placeholder.co/400/400){fig-alt="Alt"}

0 comments on commit 9585cf8

Please sign in to comment.