Skip to content

fix(html): preserve text after nested list items - #4450

Closed
kamran-nizamani wants to merge 14 commits into
docling-project:mainfrom
kamran-nizamani:fix/html-nested-list-trailing-text-4422
Closed

kamran-nizamani wants to merge 14 commits into
docling-project:mainfrom
kamran-nizamani:fix/html-nested-list-trailing-text-4422

Conversation

@kamran-nizamani

Copy link
Copy Markdown

Summary

Fixes #4422.

When a list item contains a nested list or table, text that follows the nested block was previously included in the outer list item's text and emitted before the nested content.

This change:

  • extracts only the list item's leading text before the first nested list/table;
  • emits content after nested blocks in DOM order under the outer list item;
  • covers nested lists, nested tables, and description-list items with regression tests.

Testing

Added regression coverage in tests/test_backend_html.py for the reported nested-list case and the analogous nested-table/description-list cases.

Closes #4422

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

❌ DCO Check Failed

Hi @kamran-nizamani, your pull request has failed the Developer Certificate of Origin (DCO) check.

This repository supports remediation commits, so you can fix this without rewriting history — but you must follow the required message format.


🛠 Quick Fix: Add a remediation commit

Run this command:

git commit --allow-empty -s -m "DCO Remediation Commit for Kamran Khan <kamrannizamani35@gmail.com>

I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 00c6ef6b786a2b25fe034ab03138c4d3564f9f09
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 33a20b838f95188c441cd7fad3e3b6a7805c9f5f
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 06cc0924281352ffbf5da8888f3e37a3ed8a753b
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 61c5a4d9e41f110700b44351708e3620bd95b751
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: aae632e015f712563e07720e6ca60dec602343d7
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: f02e090e9456ca6982fa2d4931b23ac99bfe1616
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 629a1dac4240865b3a27db1b386fb4d84e5f10d1
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: c7e4592ffeef763f8694552634f8f6f7ec226f58
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 2ae59b346fcd5485aa76200b25fea155bf9faa07
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: e3dec96bde4fabe6cda958b12eb57d749f3e7078"
git push

🔧 Advanced: Sign off each commit directly

For the latest commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits:

git rebase --signoff origin/main
git push --force-with-lease

More info: DCO check report

I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 00c6ef6
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 33a20b8
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 00c6ef6
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 33a20b838f95188c441cd7fad3e3b6a780c9f5f

Signed-off-by: Kamran Khan <kamrannizamani35@gmail.com>
@mergify

mergify Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 00c6ef6
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 33a20b8

Signed-off-by: Kamran Khan <kamrannizamani35@gmail.com>
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 00c6ef6
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 33a20b838f95188c441cd7fad3e3b6a780c9f5f
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 06cc092

Signed-off-by: Kamran Khan <kamrannizamani35@gmail.com>
@morten-lagabote

Copy link
Copy Markdown

Two things I noticed while testing this branch:

  • tests/test_backend_html.py fails at collection: the new test is inserted between the existing @pytest.mark.parametrize("inner", ...) decorator and test_nested_table_in_list_item_wrappers, so the decorator now applies to test_nested_block_content_preserves_following_text_order.
  • An item without text before its nested list loses the text after it: <ul><li><ul><li>x</li></ul>After</li><li>b</li></ul> gives - x\n- b (main gives - After\n - x\n- b).

The non-<li> children part also overlaps with #4440 (#4424).

@PeterStaar-IBM
PeterStaar-IBM requested review from ceberam and maxmnemonic and removed request for maxmnemonic September 30, 2026 03:45
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.33333% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/html_backend.py 49.33% 29 Missing and 9 partials ⚠️

📢 Thoughts on this report? Let us know!

I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: f02e090
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 629a1da
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: c7e4592
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: 2ae59b3
I, Kamran Khan <kamrannizamani35@gmail.com>, hereby add my Signed-off-by to this commit: e3dec96

Signed-off-by: Kamran Khan <kamrannizamani35@gmail.com>
@ceberam

ceberam commented Oct 1, 2026

Copy link
Copy Markdown
Member

@kamran-nizamani Thanks for your support and willingness to enhance Docling library! Before implementing a fix, we first had to agree with the new contract on floating elements inside an HTML list and this is what we are currently discussing with @morten-lagabote , the author of the issues #4422 and #4424. In addition, these issues should be best addressed together.
I would then suggest that we close this PR and we follow up with #4422, #4424, and the PR #4440 .

@kamran-nizamani

Copy link
Copy Markdown
Author

Thanks for the clarification, @ceberam.

That makes sense. I agree that it would be better to define the new contract for floating elements inside HTML lists first and address #4422 and #4424 together.

I’m happy to close this PR and follow up on the agreed approach in #4422, #4424, and PR #4440.

Thanks for the guidance!

@ceberam ceberam closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML backend: text after a nested list inside <li> is merged into the item and moved before the nested items

3 participants