Skip to content

Commit 4771b8c

Browse files
check for cell-output-display class defensively
fixes a crash with unsupported tbl-cap/renderings combo (it won't work right but it shouldn't crash)
1 parent 8a22e44 commit 4771b8c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/resources/filters/quarto-post/cell-renderings.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function choose_cell_renderings()
1212
return {
1313
Div = function(div)
1414
-- Only process cell div with renderings attr
15-
if not div.classes:includes("cell") or not div.attributes["renderings"] then
15+
if not div.classes or not div.classes:includes("cell") or not div.attributes["renderings"] then
1616
return nil
1717
end
1818
local renderingsJson = div.attributes['renderings']
@@ -24,7 +24,7 @@ function choose_cell_renderings()
2424
local cods = {}
2525
local firstCODIndex = nil
2626
for i, cellOutput in ipairs(div.content) do
27-
if cellOutput.classes:includes("cell-output-display") then
27+
if cellOutput.classes and cellOutput.classes:includes("cell-output-display") then
2828
if not firstCODIndex then
2929
firstCODIndex = i
3030
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "knitr dark mode - gt"
3+
brand:
4+
light: united-brand.yml
5+
dark: slate-brand.yml
6+
execute:
7+
echo: false
8+
warning: false
9+
---
10+
11+
```{r}
12+
#| echo: false
13+
#| warning: false
14+
library(gt)
15+
16+
gt_brand <- function(brand_yml) {
17+
brand <- yaml::yaml.load_file(brand_yml)
18+
return(function(table) {
19+
table |>
20+
tab_options(
21+
table.background.color = brand$color$background,
22+
table.font.color = brand$color$foreground,
23+
)
24+
})
25+
}
26+
united_theme <- gt_brand("united-brand.yml")
27+
slate_theme <- gt_brand("slate-brand.yml")
28+
```
29+
30+
This example will lose the caption, because combining `tbl-cap` with `renderings` is not supported.
31+
32+
But it should not crash.
33+
34+
35+
::: {#tbl-cap-cross}
36+
37+
```{r}
38+
#| renderings: [light, dark]
39+
#| tbl-cap: a caption
40+
caws <- head(mtcars) %>% gt()
41+
42+
caws |> united_theme()
43+
44+
caws |> slate_theme()
45+
```
46+
47+
:::
48+
49+
Here's a [link](https://example.com).
50+
51+
{{< lipsum 3 >}}

0 commit comments

Comments
 (0)