Skip to content

Commit

Permalink
Merge pull request #7305 from quarto-dev/bugfix/7917b
Browse files Browse the repository at this point in the history
better fix for #7197 and fenced code blocks
  • Loading branch information
cscheid authored Oct 20, 2023
2 parents 4bdb9b7 + d59b333 commit f56cd9c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/resources/filters/quarto-pre/parsefiguredivs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -583,23 +583,24 @@ function forward_cell_subcaps()
return nil
end
-- now we attempt to insert subcaptions where it makes sense for them to be inserted

if is_regular_node(subdiv.content[1], "Table") then
subdiv.content[1].caption.long = quarto.utils.as_blocks(pandoc.Str(subcaps[index]))
subdiv.content[1].identifier = div.identifier .. "-" .. tostring(index)
index = index + 1
return subdiv
end

local fig = discoverFigure(subdiv.content[1], false) or discoverLinkedFigure(subdiv.content[1], false)
if fig ~= nil then
fig.caption = quarto.utils.as_inlines(pandoc.Str(subcaps[index]))
fig.identifier = div.identifier .. "-" .. tostring(index)
index = index + 1
return subdiv
end

return nil
subdiv.content = _quarto.ast.walk(subdiv.content, {
Table = function(pandoc_table)
pandoc_table.caption.long = quarto.utils.as_blocks(pandoc.Str(subcaps[index]))
pandoc_table.identifier = div.identifier .. "-" .. tostring(index)
index = index + 1
return pandoc_table
end,
Para = function(maybe_float)
local fig = discoverFigure(maybe_float, false) or discoverLinkedFigure(maybe_float, false)
if fig ~= nil then
fig.caption = quarto.utils.as_inlines(pandoc.Str(subcaps[index]))
fig.identifier = div.identifier .. "-" .. tostring(index)
index = index + 1
return maybe_float
end
end,
})
return subdiv
end
})
if index ~= 1 then
Expand Down
33 changes: 33 additions & 0 deletions tests/docs/smoke-all/2023/10/19/7197b.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: "Table subcaption issue"
format: html
_quarto:
tests:
html:
ensureFileRegexMatches:
-
- "\\(a\\) Cars"
- "\\(b\\) Pressure"
- []
ensureHtmlElements:
-
- "a[href=\"#tbl-example\"].quarto-xref"
- "a[href=\"#tbl-example-1\"].quarto-xref"
- "a[href=\"#tbl-example-2\"].quarto-xref"
---


```{r}
#| label: tbl-example
#| tbl-cap: "Example"
#| tbl-subcap:
#| - "Cars"
#| - "Pressure"
#| echo: fenced
library(knitr)
kable(head(cars))
kable(head(pressure))
```

See @tbl-example-1, @tbl-example-2, @tbl-example.

0 comments on commit f56cd9c

Please sign in to comment.