From 545a7ac38eb54ddb6039473f3cc55fd6d6f19fc1 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 24 Oct 2023 10:42:53 -0700 Subject: [PATCH 1/2] use H float placement inside callouts. Closes #7334. --- src/resources/filters/quarto-post/latex.lua | 18 ++++++++++++++++-- tests/docs/smoke-all/2023/10/24/7334.qmd | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/docs/smoke-all/2023/10/24/7334.qmd diff --git a/src/resources/filters/quarto-post/latex.lua b/src/resources/filters/quarto-post/latex.lua index a472e4a28c..ac4bd6a9c9 100644 --- a/src/resources/filters/quarto-post/latex.lua +++ b/src/resources/filters/quarto-post/latex.lua @@ -207,7 +207,19 @@ function render_latex() -- require special handling local hasVerbatimInNotes = false local noteContents = {} - local nodeContent = node.content:walk({ + local lifted_contents = pandoc.Blocks({}) + + local nodeContent = _quarto.ast.walk(node.content, { + traverse = "topdown", + FloatRefTarget = function(float, float_node) + if float.identifier ~= nil then + local ref = refType(float.identifier) + if ref ~= nil then + float.attributes[ref .. "-pos"] = "H" + return float + end + end + end, Note = function(el) tappend(noteContents, {el.content}) el.content:walk({ @@ -235,7 +247,7 @@ function render_latex() local endEnvironment = callout.endInlines local calloutContents = callout.contents if calloutContents == nil then - calloutContents = pandoc.List({}) + calloutContents = pandoc.Blocks({}) end if lua_type(nodeContent) == "table" then @@ -270,6 +282,8 @@ function render_latex() end tappend(calloutContents, v) end + + calloutContents:extend(lifted_contents) -- Enable fancyvrb if verbatim appears in the footnotes if hasVerbatimInNotes then diff --git a/tests/docs/smoke-all/2023/10/24/7334.qmd b/tests/docs/smoke-all/2023/10/24/7334.qmd new file mode 100644 index 0000000000..e7db595163 --- /dev/null +++ b/tests/docs/smoke-all/2023/10/24/7334.qmd @@ -0,0 +1,19 @@ +--- +title: "table in a div" +format: + html: default + pdf: default +--- +Table in a div + +::: callout-tip +```{r, echo=FALSE, message=FALSE, warning=FALSE} +#| label: tbl-table1 +#| tbl-cap: "A table" +library(tidyverse) +table <- tribble(~a, ~b, ~c, + "text", 1, "Long text", + "others", 2, "Long text") +knitr::kable(table) +``` +::: \ No newline at end of file From e9845edfa2afee66b87cb9ef5b86e8aae6913ffa Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 24 Oct 2023 10:43:14 -0700 Subject: [PATCH 2/2] allow float placement control for more than just figures --- src/resources/filters/layout/latex.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/resources/filters/layout/latex.lua b/src/resources/filters/layout/latex.lua index 55f4c52f5a..1711cb0a77 100644 --- a/src/resources/filters/layout/latex.lua +++ b/src/resources/filters/layout/latex.lua @@ -516,7 +516,8 @@ function latexFigurePosition(el, env) if env == kMarginFigureEnv then return attribute(el, kOffset, nil) else - return attribute(el, kFigPos, nil) + local prefix = refType(el.identifier) or "fig" + return attribute(el, prefix .. "-pos", nil) end end