Skip to content

Commit b6ceaf3

Browse files
authored
hide conditional content from lua filters (#4870)
* make conditional content invisible to filters. Closes #4867 * smoke test
1 parent 5d2c86f commit b6ceaf3

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/resources/filters/quarto-pre/content-hidden.lua

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ local kWhenProfile = "when-profile"
1010
local kUnlessProfile = "unless-profile"
1111
local kConditions = pandoc.List({kWhenFormat, kUnlessFormat, kWhenProfile, kUnlessProfile})
1212

13+
function is_visible(node)
14+
local profiles = pandoc.List(param("quarto_profile", {}))
15+
local match = propertiesMatch(node.condition, profiles)
16+
if node.behavior == kContentVisible then
17+
return match
18+
elseif node.behavior == kContentHidden then
19+
return not match
20+
else
21+
crash_with_stack_trace()
22+
return false
23+
end
24+
end
25+
1326
_quarto.ast.add_handler({
1427
class_name = { kContentVisible, kContentHidden },
1528

@@ -39,21 +52,13 @@ _quarto.ast.add_handler({
3952

4053
render = function(node)
4154
local el = node.node
42-
local profiles = pandoc.List(param("quarto_profile", {}))
43-
local visible
44-
if node.behavior == kContentVisible then
45-
clearHiddenVisibleAttributes(el)
46-
visible = propertiesMatch(node.condition, profiles)
47-
elseif node.behavior == kContentHidden then
48-
clearHiddenVisibleAttributes(el)
49-
visible = not propertiesMatch(node.condition, profiles)
50-
else
51-
crash_with_stack_trace()
52-
end
55+
local visible = is_visible(node)
56+
clearHiddenVisibleAttributes(el)
5357
if visible then
5458
return el.content
59+
else
60+
return {}
5561
end
56-
return {}
5762
end,
5863

5964
constructor = function(tbl)
@@ -74,9 +79,13 @@ _quarto.ast.add_handler({
7479
end,
7580

7681
inner_content = function(tbl)
77-
return {
78-
content = tbl.node.content,
79-
}
82+
if is_visible(tbl) then
83+
return {
84+
content = tbl.node.content,
85+
}
86+
else
87+
return {}
88+
end
8089
end,
8190

8291
set_inner_content = function(tbl, content)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: issue-4867
3+
format: latex
4+
_quarto:
5+
tests:
6+
latex:
7+
ensureFileRegexMatches:
8+
- []
9+
- ["geometry"] # geometry package triggers on column-screen div (and shouldn't here)
10+
---
11+
12+
## Introduction
13+
14+
:::{.content-visible when-format="HTML}
15+
::::{.column-screen}
16+
Hello
17+
::::
18+
:::

0 commit comments

Comments
 (0)