From b9bf1ece6ef1b1a0ddad7096624df43e305cb6f5 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 1 Apr 2026 17:35:38 +0200 Subject: [PATCH 1/2] 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. --- src/resources/pandoc/datadir/_utils.lua | 2 +- .../lua/quarto-utils-is-empty-node/test.lua | 26 +++++++++++++++++++ .../lua/quarto-utils-is-empty-node/test.qmd | 7 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.lua create mode 100644 tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.qmd diff --git a/src/resources/pandoc/datadir/_utils.lua b/src/resources/pandoc/datadir/_utils.lua index b312fa2d048..2ea4b0580c1 100644 --- a/src/resources/pandoc/datadir/_utils.lua +++ b/src/resources/pandoc/datadir/_utils.lua @@ -592,7 +592,7 @@ local function is_empty_node (node) return not next(node.caption) elseif node.text then -- looks like a code node or text node - return node.text ~= '' + return node.text == '' else -- Not sure what this is, but it's probably not empty. return false diff --git a/tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.lua b/tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.lua new file mode 100644 index 00000000000..4fd3d8fe7a2 --- /dev/null +++ b/tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.lua @@ -0,0 +1,26 @@ +function Pandoc(doc) + local is_empty = quarto.utils.is_empty_node + + -- nil is empty + assert(is_empty(nil) == true, "nil should be empty") + + -- text nodes: Str + assert(is_empty(pandoc.Str("")) == true, "Str('') should be empty") + assert(is_empty(pandoc.Str("hello")) == false, "Str('hello') should not be empty") + + -- text nodes: Code + assert(is_empty(pandoc.Code("")) == true, "Code('') should be empty") + assert(is_empty(pandoc.Code("x")) == false, "Code('x') should not be empty") + + -- text nodes: RawInline + assert(is_empty(pandoc.RawInline("html", "")) == true, "RawInline('') should be empty") + assert(is_empty(pandoc.RawInline("html", "
")) == false, "RawInline('
') should not be empty") + + -- container nodes: empty vs non-empty + assert(is_empty(pandoc.Para({})) == true, "Para({}) should be empty") + assert(is_empty(pandoc.Para({pandoc.Str("hi")})) == false, "Para with content should not be empty") + + -- empty table + assert(is_empty({}) == true, "empty table should be empty") + assert(is_empty({1}) == false, "non-empty table should not be empty") +end diff --git a/tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.qmd b/tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.qmd new file mode 100644 index 00000000000..3d0c81aa31a --- /dev/null +++ b/tests/docs/smoke-all/lua/quarto-utils-is-empty-node/test.qmd @@ -0,0 +1,7 @@ +--- +title: is_empty_node tests +filters: + - test.lua +--- + +Some content. From e724742c6aa756145918eb7db405564d05f305d0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 1 Apr 2026 17:44:38 +0200 Subject: [PATCH 2/2] Add changelog entry for is_empty_node fix (#14297) --- news/changelog-1.10.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/news/changelog-1.10.md b/news/changelog-1.10.md index d43a69482c4..fd0baeae203 100644 --- a/news/changelog-1.10.md +++ b/news/changelog-1.10.md @@ -21,6 +21,10 @@ All changes included in 1.10: - ([#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. +## Lua API + +- ([#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`). + ## Other fixes and improvements - ([#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.