Fix inverted logic in quarto.utils.is_empty_node for text nodes#14297
Open
Fix inverted logic in quarto.utils.is_empty_node for text nodes#14297
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When calling
quarto.utils.is_empty_node()on text nodes likeStr,Code, orRawInline, the function returns inverted results:truefor non-empty nodes andfalsefor empty ones.Root Cause
The
.textbranch inis_empty_nodeusednode.text ~= ''(not-equal) instead ofnode.text == ''(equal). Every other branch follows the pattern of returningtruewhen the node has no content — for example,not next(node.content)returnstruewhen the content list is empty. The text branch should follow the same semantics:Str('')is empty just asPara({})is empty — a node of the right type with nothing in it.Fix
Change the operator from
~=to==so text nodes follow the same emptiness semantics as container nodes.Internal callers all pass container nodes (captions, preambles) so nothing was visibly broken, but extension authors calling the public API on text nodes get wrong results.