Skip to content

Commit 0501d07

Browse files
committed
Ensure that column options are forwarded to widgets and so on
```{r} #| label: fig-widget #| fig-cap: "An htmlwidget figure" #| fig-column: margin #| out-width: 100% #| echo: fenced plotly::plot_ly(data = cars, type = "scatter", mode = "markers", x = ~speed, y = ~dist) ```
1 parent b23611c commit 0501d07

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/resources/filters/layout/columns-preprocess.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,18 @@ function resolveColumnClassesForCodeCell(el)
8484
-- no known children were discovered, apply the column classes to the cell output display itself
8585
if not forwarded then
8686

87-
local colClasses = computeClassesForScopedColumns(el)
88-
local capClasses = computeClassesForScopedCaption(el)
89-
applyClasses(colClasses, capClasses, el, childEl, childEl)
87+
-- figure out whether there are tables inside this element
88+
-- if so, use tbl scope, otherwise treat as a fig
89+
local tableCount = countTables(el)
90+
local scope = 'fig'
91+
if tableCount > 0 then
92+
scope = 'tbl'
93+
end
94+
95+
-- forward the classes from the proper scope onto the cell-output-display div
96+
local colClasses = computeClassesForScopedColumns(el, scope)
97+
local capClasses = computeClassesForScopedCaption(el, scope)
98+
applyClasses(colClasses, capClasses, el, childEl, childEl, scope)
9099

91100
end
92101
end

src/resources/filters/layout/html.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ function renderHtmlFigure(el, render)
189189
figureDiv.attr.classes:insert("quarto-figure")
190190
figureDiv.attr.classes:insert("quarto-figure-" .. align)
191191

192+
-- also forward any column or caption classes
193+
local currentClasses = el.attr.classes
194+
for _,k in pairs(currentClasses) do
195+
if isCaptionClass(k) or isColumnClass(k) then
196+
figureDiv.attr.classes:insert(k)
197+
end
198+
end
199+
192200
-- begin figure
193201
figureDiv.content:insert(pandoc.RawBlock("html", "<figure>"))
194202

src/resources/filters/layout/layout.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import("../common/format.lua")
3939
import("../common/refs.lua")
4040
import("../common/layout.lua")
4141
import("../common/figures.lua")
42+
import("../common/tables.lua")
4243
import("../common/options.lua")
4344
import("../common/params.lua")
4445
import("../common/meta.lua")

0 commit comments

Comments
 (0)