fix(asciidoc): block titles, picture parenting, skipped headings, and list dedent - #4171
Open
ceberam wants to merge 3 commits into
Open
fix(asciidoc): block titles, picture parenting, skipped headings, and list dedent#4171ceberam wants to merge 3 commits into
ceberam wants to merge 3 commits into
Conversation
…evels - Emit block titles as captions on FloatingItems (picture, table, code) and as bold paragraphs before lists and other non-floating elements - Fix pictures always parented to body root instead of current section - Fix section headings with skipped levels landing at body root Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
…evel Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Contributor
|
✅ DCO Check Passed Thanks @ceberam, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
ceberam
marked this pull request as ready for review
September 4, 2026 09:59
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Fix several structural bugs in the AsciiDoc backend
This PR fixes four independent structural bugs in
AsciiDocBackenddiscovered when reviewing PR #4118 , adds a new test document that exercises all caption variants, and tightens an existing test.Block titles attached to the wrong element
In AsciiDoc, a line starting with
.immediately followed by text (e.g..Procedure) is a block title — it captions the immediately following element, not the preceding one.The backend was flushing pending block-title text as a standalone
CAPTIONitem at the moment it encountered the next block, so the caption ended up before or after the wrong element in the DoclingDocument body.The new contract, documented in
_parse's docstring:CAPTION-labelledTextItemand attached via thecaption=parameter, so it participates in the standard structural caption relationship.PARAGRAPHTextIteminserted immediately before the element it precedes.GroupItemhas no caption slot, so this is the closest correct representation while preserving reading order.Pictures always parented to the document body root
doc.add_picturewas called withparent=Nonefor all non-list contexts, unconditionally placing every picture at the document body root regardless of which section it appeared in. Pictures are now parented withself._get_current_parent(parents), matching the behaviour of every other element type.Section headings with skipped levels landing at the body root
When heading levels are skipped in the source (e.g.
==followed directly by====with no===in between),parents[level - 1]isNoneand the heading was silently placed at the body root. The backend now walks down fromlevel - 1to find the nearest populated ancestor, so skipped-level headings nest under the closest available parent instead of floating to the top.List items orphaned when dedenting past the base indent
When a list started with an indented item and a later item dedented all the way back to indent 0, the dedent loop cleared the only list group from
parentsand left no valid parent for the dedented item.add_list_itemthen receivedparent=None, causing docling-core to emitDeprecationWarning: ListItem parent must be a list group, creating one on the flyand create a structurally orphaned implicit group.The loop now stops before clearing the last remaining group: if
indents[level - 1]isNonethere is no outer group to fall back to, so the current group is kept as the list root and the dedented item is added to it.New test document:
asciidoc_05.asciidocA new example file and its groundtruth markdown have been added to cover all four block-title targets in one document:
.Figure 1: …before animage::→ caption attached toPictureItem.Important Prerequisites/.Steps to complete setupbefore lists → bold paragraphs before each list.Example configuration payloadbefore a....literal block → caption attached toCodeItem.Supported output formatsbefore a|===table → caption attached toTableItemTest improvements
The
test_local_images_are_embedded_and_missing_images_do_not_break_exporttest now wraps the conversion inpytest.warns(UserWarning, match="Could not process an image").This both asserts that the warning is raised when images are missing (the warning becoming a test contract) and prevents it from leaking into the test-run output.