Skip to content

Commit

Permalink
Merge pull request #10166 from quarto-dev/bugfix/10165
Browse files Browse the repository at this point in the history
lua, shortcodes - don't remove attribute values that don't match lpeg expression
  • Loading branch information
cscheid authored Jun 27, 2024
2 parents a8a138f + 3515442 commit 30967bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/resources/filters/customnodes/shortcodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ function shortcodes_filter()
return pandoc.utils.stringify(result)
end,
})
local function apply_code_shortcode(text)
return shortcode_lpeg.wrap_lpeg_match(code_shortcode, text) or text
end

local filter

local block_handler = function(node)
Expand Down Expand Up @@ -261,14 +265,14 @@ function shortcodes_filter()
return
end

el.text = shortcode_lpeg.wrap_lpeg_match(code_shortcode, el.text)
el.text = apply_code_shortcode(el.text)
return el
end

local attr_handler = function(el)
for k,v in pairs(el.attributes) do
if type(v) == "string" then
el.attributes[k] = shortcode_lpeg.wrap_lpeg_match(code_shortcode, v)
el.attributes[k] = apply_code_shortcode(v)
end
end
return el
Expand Down Expand Up @@ -302,12 +306,12 @@ function shortcodes_filter()
RawInline = code_handler,
Image = function(el)
el = attr_handler(el)
el.src = shortcode_lpeg.wrap_lpeg_match(code_shortcode, el.src)
el.src = apply_code_shortcode(el.src)
return el
end,
Link = function(el)
el = attr_handler(el)
el.target = shortcode_lpeg.wrap_lpeg_match(code_shortcode, el.target)
el.target = apply_code_shortcode(el.target)
return el
end,
Span = function(el)
Expand Down
13 changes: 13 additions & 0 deletions tests/docs/smoke-all/2024/06/27/10165.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: test
_quarto:
tests:
html:
ensureHtmlElements:
- ["img[alt='']", "img#second[alt='']"]
- []
---

![]({{< placeholder >}}){width=45 alt=""}

![](foo.png){#second width=45 alt=""}

0 comments on commit 30967bd

Please sign in to comment.