fix(logic): correct two structural logic bugs in MetadataFigure.run() - #65
Merged
Conversation
1. Wrong type for self.content when :number: is used without a caption:
self.content was assigned a plain list instead of the StringList that
Figure.run() expects. Wrap the placeholder in StringList().
Additionally, detect the active builder so that the HTML invisible-
caption span is only injected for HTML-family builders; other builders
(LaTeX, PDF, ...) now receive an RST escaped-space placeholder instead
of literal HTML markup.
2. {cite:empty} reference node appended directly to the document root:
self.state.document += para inserts the paragraph at the top level of
the document tree, corrupting its structure. The paragraph is now
collected in _extra_prefix_nodes and prepended to the returned node
list so that Sphinx places it at the correct location in the tree.
https://claude.ai/code/session_01ApsmWPWsKBesMV1rq2VenA
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
Two bugs that cause incorrect document tree structure or broken output in non-HTML builders.
1.
self.contentassigned a plainlistinstead ofStringList(__init__.py:547)When
:number:is used without a caption, the code injected an HTML<span>placeholder by assigning a plain Pythonlisttoself.content. The parentFigure.run()expects aStringList; passing a plain list can cause subtle failures during caption parsing.Additionally, the raw HTML
<span class="invisible-caption-text"> </span>was used regardless of the active builder. LaTeX, PDF, and other non-HTML builders render it as literal markup text, producing garbage in the output.Fix:
StringList([...]).env.app.builder.name; HTML-family builders (html,dirhtml,singlehtml,readthedocs) receive the HTML span; all other builders receive an RST escaped-space (\\) which produces no visible output.2.
{cite:empty}reference node appended to the document root (__init__.py:592)self.state.document += parainserts the citation-registration paragraph directly at the top level of the Sphinx document tree. This bypasses the normal document-tree structure and can result in an extra paragraph appearing in unexpected locations or breaking document traversal.Fix: collect the node in
_extra_prefix_nodesand prepend it to the returned node list at the end ofrun(). Sphinx then inserts it at the correct position in the tree relative to the figure.Test plan
:number:on a figure without a caption; build with the LaTeX builder and confirm no raw HTML appears in the.texoutput.:bib:with an existing key; confirm the build completes and the citation reference does not appear as an extra visible paragraph anywhere in the HTML output.https://claude.ai/code/session_01ApsmWPWsKBesMV1rq2VenA