Repository navigation
fix(html): keep an image caption with its picture - #5037
sarankumar1325 wants to merge 1 commit into
Conversation
An image caption (from a <figcaption>, a linked image or the alt text) was added without a parent, so it went to the document body. In a document with sections, the caption was left outside the section of its picture, after the section's other content. Add the caption as a child of its picture, as the PDF pipeline does, so it stays with the picture in its section or rich table cell. Markdown output does not change. The HTML reference data is regenerated for the new parent. Resolves docling-project#5036 Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @sarankumar1325, all your commits are properly signed off. 🎉 |
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/
|
AI triage (advisory)Checked commit The HTML backend now adds an image caption as a child of its picture and links it in Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
Reference data changes
Assessment: expected. The code change makes the caption a child of its picture instead of The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 166d32bb1b. It read the code and did not run it.
I checked the HTML image caption hierarchy change and its test coverage. Image captions now attach to their picture item as children and keep the correct section structure without breaking document exports.
A maintainer makes the merge decision. This review never approves the pull request.
An image caption (taken from a
<figcaption>, a linked image, or the alt text) was added withdoc.add_text()and no parent, so it went intobody. In a page with sections, the caption ended up outside its picture's section: between section "One" and section "Two" in the issue's example._emit_imagenow adds the picture first, then adds the caption as a child of the picture and links it incaptions. The PDF reading-order model does the same. As a result, the caption stays with its picture when the picture is a child of a section and also whengroup_cell_elementsmoves the picture into a rich table cell group.Issue resolved by this Pull Request:
Resolves #5036
Checklist:
Review evidence:
body.childrenwas the title "One", then the caption "Caption text", then the title "Two". Section "One" held only the picture and "Para one.".body.childrenis the two titles. Section "One" holds the picture and "Para one.". The caption is the picture's only child and is still inpicture.captions.test_image_caption_stays_in_the_section_of_its_imageis parametrized for a<figcaption>and an alt-text caption. Both cases fail onmainand pass with this change.DOCLING_GEN_TEST_DATA=1forexample_01,example_01_images,html_rich_table_cells,hyperlink_02,hyperlink_05andwiki_duck. In the JSON, the only change is the parent of each image caption, which moves from#/bodyto its picture. The.itxttrees list the caption under the picture: once as the child and once fromcaptions. No Markdown reference file changed.uv run pytest tests/test_backend_html.py tests/test_backend_markdown.py tests/test_backend_mhtml*.py: 194 passed, 1 skipped.ruff format --checkandruff checkare clean.ty check docling/backend/html_backend.pyreports the same 27 diagnostics as onmain.This fix was prepared with AI assistance; I reviewed the change and ran the checks above.