Skip to content

Commit 96dc728

Browse files
authored
Fix inverted logic in quarto.utils.is_empty_node for text nodes (#14297)
* Fix inverted logic in quarto.utils.is_empty_node for text nodes The text branch (`node.text`) used `~=` (not-equal) where it should use `==` (equal), causing is_empty_node to return true for non-empty text nodes and false for empty ones. Text nodes like Str and Code should follow the same emptiness semantics as container nodes like Para and Div: a Str('') is empty just as Para({}) is empty -- a node of the right type but with nothing in it. Internal callers all pass container nodes (caption, preamble) so nothing was visibly broken, but extension authors calling the public API on text nodes get wrong results. * Add changelog entry for is_empty_node fix (#14297)
1 parent 03138ed commit 96dc728

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

news/changelog-1.10.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ All changes included in 1.10:
2222

2323
- ([#14250](https://github.com/quarto-dev/quarto-cli/issues/14250)): Fix `quarto create` producing read-only files when Quarto is installed via system packages (e.g., `.deb`). Files copied from installed resources now have user-write permission ensured.
2424

25+
## Lua API
26+
27+
- ([#14297](https://github.com/quarto-dev/quarto-cli/pull/14297)): Fix `quarto.utils.is_empty_node()` returning inverted results for text nodes (`Str`, `Code`, `RawInline`).
28+
2529
## Other fixes and improvements
2630

2731
- ([#6651](https://github.com/quarto-dev/quarto-cli/issues/6651)): Fix dart-sass compilation failing in enterprise environments where `.bat` files are blocked by group policy.

src/resources/pandoc/datadir/_utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ local function is_empty_node (node)
592592
return not next(node.caption)
593593
elseif node.text then
594594
-- looks like a code node or text node
595-
return node.text ~= ''
595+
return node.text == ''
596596
else
597597
-- Not sure what this is, but it's probably not empty.
598598
return false
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function Pandoc(doc)
2+
local is_empty = quarto.utils.is_empty_node
3+
4+
-- nil is empty
5+
assert(is_empty(nil) == true, "nil should be empty")
6+
7+
-- text nodes: Str
8+
assert(is_empty(pandoc.Str("")) == true, "Str('') should be empty")
9+
assert(is_empty(pandoc.Str("hello")) == false, "Str('hello') should not be empty")
10+
11+
-- text nodes: Code
12+
assert(is_empty(pandoc.Code("")) == true, "Code('') should be empty")
13+
assert(is_empty(pandoc.Code("x")) == false, "Code('x') should not be empty")
14+
15+
-- text nodes: RawInline
16+
assert(is_empty(pandoc.RawInline("html", "")) == true, "RawInline('') should be empty")
17+
assert(is_empty(pandoc.RawInline("html", "<br>")) == false, "RawInline('<br>') should not be empty")
18+
19+
-- container nodes: empty vs non-empty
20+
assert(is_empty(pandoc.Para({})) == true, "Para({}) should be empty")
21+
assert(is_empty(pandoc.Para({pandoc.Str("hi")})) == false, "Para with content should not be empty")
22+
23+
-- empty table
24+
assert(is_empty({}) == true, "empty table should be empty")
25+
assert(is_empty({1}) == false, "non-empty table should not be empty")
26+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: is_empty_node tests
3+
filters:
4+
- test.lua
5+
---
6+
7+
Some content.

0 commit comments

Comments
 (0)