Repository navigation
fix(md): keep a heading or list item without text from taking a later block's text - #4870
Conversation
… block's text Signed-off-by: Lubaba Khalid <129605617+LubabaKhalid@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @LubabaKhalid, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. 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 PR fixes the Markdown backend. A heading or list item with no text run (an image without alt text, or only inline HTML) now becomes an item with empty text. It no longer takes the text of a later block. Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 8544d9431b. It read the code and did not run it.
I found no defect that blocks the merge. I traced the new flush paths in docling/backend/md_backend.py for list items and headings that hold only an image without alt text, or only inline HTML. They flush the pending payload with empty text before a later block can take it. The nested-list case also works: the flush runs after the first child, so a nested list attaches to the right item.
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! |
|
@dolfim-ibm @PeterStaar-IBM could you please review this PR when you have time? Thank you! |
A Markdown heading or list item does not create its item right away.
_iterate_elements()pushes a payload oncreation_stack, and the first text run or code span of its content creates the item with that text. Two kinds of content emit neither:1. or# ;# <img src="logo.png" width="80">.The payload then stays on the stack, and the next text run of the document, in a later block, creates the item with its own text:
This change:
An image with alt text keeps its current output, because its alt text is a text run.
Checklist:
Review evidence:
export_to_markdown()before and after:1. A list item with only an image
main:This PR (the same as the HTML backend gives for
<ol><li><img src="a.png"></li>...):2. A nested list under a list item with only an image
main:<!-- image -->,- nested,- nested,- next(the nested item is created twice).This PR:
-,<!-- image -->,- nested,- next.3. A heading with only an image or only inline HTML
main# +Intro paragraph.<!-- image -->,# Intro paragraph.#,<!-- image -->,Intro paragraph.# <img src="logo.png" width="80">+Intro paragraph.# Intro paragraph.#,Intro paragraph./===+Intro paragraph.<!-- image -->,# Intro paragraph.#,<!-- image -->,Intro paragraph.Reference data: no change.
Tests: three new tests in
tests/test_backend_markdown.py, with five cases: the list item with only an image (markers, texts, picture under the item), the nested list, and the three heading inputs. All five fail onmain.Checks:
uv run pytest tests/test_backend_markdown.py tests/test_backend_markdown_images.py tests/test_backend_html.py tests/test_backend_epub.py tests/test_backend_text_encoding.py: 228 passed, 1 skippeduv run prek run --files <changed files>: all hooks passed