Fix LaTeX builder crash on tables with no body rows#14291
Open
veeceey wants to merge 1 commit intosphinx-doc:masterfrom
Open
Fix LaTeX builder crash on tables with no body rows#14291veeceey wants to merge 1 commit intosphinx-doc:masterfrom
veeceey wants to merge 1 commit intosphinx-doc:masterfrom
Conversation
The LaTeXFootnoteVisitor.depart_table() method called next(node.findall(nodes.tbody)) which raises StopIteration when a table has header rows but no body rows (as produced by e.g. myst_parser from Markdown). Handle the missing tbody gracefully by placing any collected footnotes after the table node instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed. |
795d52a to
6bbbc96
Compare
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.
Summary
Fixes #14271.
LaTeXFootnoteVisitor.depart_table()unconditionally callsnext(node.findall(nodes.tbody)), which raisesStopIterationwhen a table has header rows but no body rows. This happens when external parsers like myst_parser produce a docutils table node tree from Markdown tables that have only a header row (e.g.| Key | P | Summary |\n| --- | --- | --- |).The fix:
next(..., None)to safely handle the missingtbodytbodyis present, behavior is unchanged (footnotes are inserted at the head of tbody)tbodyis absent, any collected table footnotes are placed after the table node instead, preserving footnote renderingTest:
test_latex_table_empty_bodywhich constructs a table node withtheadbut notbody(mirroring what myst_parser produces) and verifies thatLaTeXFootnoteVisitorprocesses it without raisingStopIterationStopIterationon the unfixed code and passes with the fixTest plan
test_latex_table_empty_bodypassesruff checkpasses on both modified files