Repository navigation
fix(html): don't spread one run's formatting or link to a whole heading - #4670
Conversation
Headings and figure captions are flattened to one text element. The first run that had a formatting or a hyperlink gave it to the whole element, so <h2>To the <i>Hibernia</i></h2> became an italic heading and a caption with one link became a link as a whole. Keep a formatting or a hyperlink only when every text run has it. Reference data: the italic heading in epub_purvis_poetry and the caption links in wiki_duck and hyperlink_05 that only covered part of the text. Signed-off-by: er-s-an <92594860+er-s-an@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @er-s-an, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
AI triage (advisory)Checked commit Fixes 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 reference data changes match exactly what the PR description predicts: the 'Hibernia' heading loses its italic, 12 wiki_duck captions lose partial hyperlinks, and only formatting/hyperlink fields change. The |
There was a problem hiding this comment.
AI first review (advisory): no blocking issue found
This review covers the full diff at 204f927f19. It read the code only. It did not run tests or code from this pull request.
This PR updates AnnotatedTextList.to_single_text_element in the HTML backend to only apply formatting or hyperlink metadata when it matches across all non-whitespace text runs. The fix resolves heading and caption metadata bleeding with targeted tests and minimal regression scope.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Issue resolved by this Pull Request:
Resolves #4668
Headings and figure captions in the HTML backend are flattened to one text element by
AnnotatedTextList.to_single_text_element(). It took the first formatting and the first hyperlinkit found and applied them to the whole element. A heading like
<h2>To the <i>Hibernia</i></h2>became an italic heading, and a caption with one link became a link as a whole.
The element now keeps a formatting or a hyperlink only when every text run has it (whitespace-only
runs are ignored). A heading that is bold or linked as a whole is unchanged. Keeping the partial
formatting itself (e.g. an inline group like list items use) would be a bigger change, so this PR
only stops reporting formatting that is not there.
Checklist:
Review evidence:
Before / after:
<h2>Section <strong>bold</strong> heading</h2>## **Section bold heading**## Section bold heading<h2><a href=...>Docs</a> and more</h2><h2><strong>All</strong> <strong>bold</strong></h2><h2><a href=...>Docs</a></h2>Reference data changes (only
formatting/hyperlinkfields change; I checked that every otherfield is identical):
tests/data/epub/groundtruth/epub_purvis_poetry.epub.{json,md}: "To the Hibernia" heading isno longer italic (only "Hibernia" is italic in the source).
tests/data/html/groundtruth/wiki_duck.html.{json,md}: 12 captions lose a link that coveredonly part of the caption (one also loses superscript from its
[49]reference). "Ringed teal",where the whole caption is the link, keeps its link.
tests/data/html/groundtruth/hyperlink_05.html.json: the captionThis is an example <a href="#caption">caption</a> for the image.is no longer linked as a whole.I edited only these fields by hand. Regenerating with
DOCLING_GEN_TEST_DATA=1also rewritesunrelated values that are already stale on main (
origquote characters in the EPUB JSON,row_spaninexample_08.html.json), so I left those out.Tests added in
tests/test_backend_html.py:test_heading_keeps_only_formatting_of_all_its_text(4 cases: partial bold, partial link, fullbold, full link)
test_caption_with_partial_link_has_no_hyperlinkThe partial cases and both e2e tests fail on main and pass with the change.
Commands:
uv run pytest tests/test_backend_html.py tests/test_backend_epub.py tests/test_backend_markdown.py tests/test_backend_mhtml.py: 160 passed, 1 skippeduv run pytest tests -k "not pdf and not ocr and not vlm and not asr": 2233 passed; the 23failures and 19 collection errors are the same on main in my environment (no docling-parse,
torchvision or LibreOffice installed)
make validate(ruff, ruff-format, ty, tach, license header, max lines): all passedNote: #3891 changes the text joining in the same function (
current_text += ...). It does notchange the formatting/hyperlink logic, but the two may need a small rebase.