Fix crash with crossref div and conditional visibility#13995
Open
Fix crash with crossref div and conditional visibility#13995
Conversation
When a div has both a cross-reference ID (e.g., #tbl-) and conditional visibility class (.content-visible), the slot content gets transformed by parsefiguredivs from Div to FloatRefTarget to Table. The render function in content-hidden.lua assumed the slot was always a Div and crashed when calling el.content on a Table. The fix checks if the rendered slot is still a Div before accessing .content. For transformed elements (Table, etc.), return the element wrapped in pandoc.Blocks. Fixes #13992 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests for conditional visibility with various custom nodes that were affected by the fix in content-hidden.lua: - Figure (FloatRefTarget) - Listing (FloatRefTarget) - Theorem (Theorem custom node) - Proof (Proof custom node) - Plain div (baseline) - Nested callout (Callout custom node) - Nested tabset (HTML-specific) - Rename table test to reflect its focus on Table (Table custom node) Each test verifies PDF, HTML, and Typst output with structure checks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
3 tasks
Document that the clearHiddenVisibleAttributes() call in ConditionalBlock render is defensive (typically a no-op) since parse() already strips visibility attrs. Kept as safety net for potential future code changes.
Collaborator
Author
|
Note on Investigation using AST tracing revealed that this cleanup call is technically a no-op for Divs inside ConditionalBlocks:
We're keeping the call as defensive programming with an explanatory comment, in case future code changes introduce attrs between parse and render. The cost is zero (no-op), but provides a safety net. This cleanup IS still necessary for Spans/CodeBlocks handled by |
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.
So I have looked into #13995 with the help of Claude Code, and tested different scenarios. I believe this could fix #13992
Summary
Rendering fails with
attempt to index a nil valuewhen a div has both:#tbl-,#fig-,#lst-).content-visible/.content-hidden)Root Cause
The
content-hidden.luarender function assumesnode.nodeis always a Div and callsel.content. However,parsefiguredivs.luatransforms crossref divs intoFloatRefTargetcustom nodes, which then render to Table/Figure/etc. When the slot content is no longer a Div, calling.contentcrashes.Fix
Check if the slot is still a regular Div before accessing
.content. For transformed elements, return them wrapped inpandoc.Blocks().Test Coverage
Added 8 test files covering various scenarios:
Fixes #13992