Skip to content

Commit 33d0b0c

Browse files
authored
Fix empty blockquote crash in revealjs output (#14586)
An empty blockquote (`> `) crashed the revealjs render because `reveal.lua` used `#b.content` as a nil guard — but in Lua `0` is truthy, so the guard passed and `b.content[1].t` indexed nil. Replaced the manual length-and-type check with `quarto.utils.match("[1]/BulletList")`, which is nil-safe by design and already used across 20+ filter callsites. Fixes #14585
1 parent c2636ff commit 33d0b0c

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎.claude/rules/filters/lua-development.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ if node.is_custom_node then
7979
end
8080
```
8181

82+
### AST Pattern Matching with `quarto.utils.match`
83+
84+
Use `quarto.utils.match()` for safe structural checks on AST nodes. It handles nil/empty content internally — no manual length or nil guards needed. Defined in `src/resources/pandoc/datadir/_utils.lua`.
85+
86+
```lua
87+
-- ✅ Correct - safe, handles empty content
88+
if quarto.utils.match("[1]/BulletList")(b) then ...
89+
90+
-- ❌ Wrong - crashes on empty content (0 is truthy in Lua)
91+
if #b.content and b.content[1].t == "BulletList" then ...
92+
93+
-- ❌ Fragile - manual nil guard, verbose
94+
if #b.content > 0 and b.content[1].t == "BulletList" then ...
95+
```
96+
97+
Selector syntax supports `/` child traversal, `[n]` nth-child, `{Type}` capture, `:child`/`:descendant` search, and CSS-like class matching:
98+
99+
```lua
100+
-- Check nested structure
101+
quarto.utils.match("Figure/[1]/Plain/[1]/Image")(fig)
102+
103+
-- Capture matched nodes (returned in a list)
104+
quarto.utils.match("[1]/{Plain}")(content)
105+
106+
-- Search direct children for class
107+
quarto.utils.match(".cell-output-display/:child/{Para}")(div)
108+
```
109+
110+
Prefer `match()` over manual `.content[1].t ==` checks — it's nil-safe, readable, and already used in 20+ filter callsites.
111+
82112
### Slot Assignment
83113

84114
Use the proxy pattern for slot modification:
@@ -285,3 +315,4 @@ These type definition files document the complete API surface.
285315
8. **Gate format inside element fns** - Constructor runs before format is resolved
286316
9. **Detect meta shape with `quarto.utils.type`** - Meta values have no `.t` tag
287317
10. **Gate expensive filters with `flags`** - Skips the whole pass when unneeded
318+
11. **Use `quarto.utils.match()` for content checks** - Nil-safe, prefer over manual `.content[1].t`

‎news/changelog-1.10.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ All changes included in 1.10:
3939
### `revealjs`
4040

4141
- ([#14354](https://github.com/quarto-dev/quarto-cli/pull/14354)): Fix trailing whitespace after author name on title slide when ORCID is not set. (author: @jnkatz)
42+
- ([#14585](https://github.com/quarto-dev/quarto-cli/issues/14585)): Fix empty blockquote (`> `) crashing render for revealjs format.
4243

4344
## Projects
4445

‎src/resources/filters/quarto-post/reveal.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function render_reveal_fixups()
6161
-- Prevent BulletList in blockquote to be made incremental with .fragment class
6262
-- https://github.com/quarto-dev/quarto-cli/issues/7715
6363
BlockQuote = function(b)
64-
if #b.content and b.content[1].t == "BulletList" then
64+
if quarto.utils.match("[1]/BulletList")(b) then
6565
b.content = pandoc.Div(b.content, pandoc.Attr('', {'blockquote-list-scaffold'}))
6666
return b
6767
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: "Empty blockquote"
3+
format: revealjs
4+
_quarto:
5+
tests:
6+
revealjs:
7+
ensureHtmlElements:
8+
- ["blockquote"]
9+
noErrors: []
10+
---
11+
12+
## Slide with empty blockquote
13+
14+
>
15+
16+
## Slide with content blockquote
17+
18+
> This is a normal blockquote

0 commit comments

Comments
 (0)