Skip to content

Commit

Permalink
Merge pull request #7972 from quarto-dev/bugfix/7045
Browse files Browse the repository at this point in the history
latex: forward fig-pos and fig-env from subfloats to parent float
  • Loading branch information
cscheid authored Dec 19, 2023
2 parents 8588cb5 + fb440f7 commit a2defe4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/resources/filters/normalize/astpipeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ function quarto_ast_pipeline()
parse_blockreftargets()
}),
},
{
name = "normalize-3",
filter = handle_subfloatreftargets(),
}
}
end
28 changes: 28 additions & 0 deletions src/resources/filters/quarto-pre/parsefiguredivs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@

local patterns = require("modules/patterns")

function handle_subfloatreftargets()
-- #7045: pull fig-pos and fig-env attributes from subfloat to parent
return {
FloatRefTarget = function(float)
local pulled_attrs = {}
local attrs_to_pull = {
"fig-pos",
"fig-env",
}
local result = _quarto.ast.walk(float, {
FloatRefTarget = function(subfloat)
for _, attr in ipairs(attrs_to_pull) do
if subfloat.attributes[attr] then
pulled_attrs[attr] = subfloat.attributes[attr]
subfloat.attributes[attr] = nil
end
end
return subfloat
end,
}) or pandoc.Div({}) -- won't happen but the lua analyzer doesn't know that
for k, v in pairs(pulled_attrs) do
float.attributes[k] = v
end
return float
end
}
end

local function process_div_caption_classes(div)
-- knitr forwards "cap-location: top" as `.caption-top`...
-- and in that case we don't know if it's a fig- or a tbl- :facepalm:
Expand Down
27 changes: 27 additions & 0 deletions tests/docs/smoke-all/2023/12/19/7045.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: "Untitled"
_quarto:
tests:
latex:
ensureFileRegexMatches:
-
- "\\\\begin\\{figure\\}\\[t\\]"
- []
---

```{python}
#| label: fig-charts
#| fig-pos: t
#| fig-cap: "Charts"
#| fig-subcap:
#| - "First"
#| - "Second"
#| layout-ncol: 2
import matplotlib.pyplot as plt
plt.plot([1,23,2,4])
plt.show()
plt.plot([8,65,23,90])
plt.show()
```

0 comments on commit a2defe4

Please sign in to comment.