Skip to content

fix(html): resolve the line break sentinel outside paragraphs - #4675

Merged
dolfim-ibm merged 2 commits into
docling-project:mainfrom
morten-lagabote:fix/html-br-sentinel
Oct 14, 2026
Merged

dolfim-ibm merged 2 commits into
docling-project:mainfrom
morten-lagabote:fix/html-br-sentinel

Conversation

@morten-lagabote

Copy link
Copy Markdown
Contributor

The backend replaces each <br> with a sentinel character (U+E000). split_by_newline() and get_text() turn it into a line break, for paragraphs and table cells. Four other places did not, so the character was left in the text and in the exports: headings and captions (to_single_text_element()), list items (_add_list_item_with_content()), <pre> blocks, and the text of checkboxes (_extract_text_excluding_tag_obj_ids()).

These places now resolve the sentinel:

  • Heading, caption, list item: a line break (\n), as in a paragraph. Consecutive <br> tags give one line break, because these items hold one paragraph.
  • <pre> block: each <br> is a newline.
  • Text of a checkbox: stays on one line, as _normalize_checkbox_text() already collapses whitespace.

A run that only holds <br> tags gives no item of its own. So in an item with formatting, a <br> between two runs gives no line break, as in a paragraph with formatting today. An <li> or a heading that only holds a <br> no longer gets the sentinel as its text.

#4670 changes another part of to_single_text_element(). The two changes merge without a conflict, and the HTML and EPUB tests pass on the combination.

Issue resolved by this Pull Request:
Resolves #4671

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

  • Before: <h2>Line one<br>Line two</h2> gives the text Line one  Line two and the Markdown ## Line one  Line two.
  • After: the text is Line one\nLine two. The Markdown is ## Line one Line two for a heading and - Line one \nLine two for a list item (fix(markdown): serialize newlines as GFM hard line breaks docling-core#721).
  • Document tree: I converted a <br> in 47 kinds of elements on main and on this branch. On main, 17 of them have U+E000 in the document or in the Markdown or HTML export. On this branch, none has. Paragraphs and table cells do not change. A <br> between two formatted runs (15 shapes) leaves no empty item.
  • Test: test_html_line_break_outside_paragraphs fails without the fix and passes with it.
  • Reference data: no change. The tests of the backends that use HTMLDocumentBackend (HTML, MHTML, EPUB, email, Markdown, XBRL, JATS, USPTO, PPTX) pass with the existing ground truth: 324 passed, 1 skipped.
  • Checks: the hooks pass on the two changed files (Ruff, ty, Tach).
  • Not run: the PDF and OCR test suites. This change does not touch them.

A `<br>` is replaced by a sentinel character (U+E000), which
`split_by_newline()` and `get_text()` turn into a line break for
paragraphs and table cells. Headings, captions, list items, `<pre>`
blocks and the text of checkboxes did not resolve it, so the character
was left in the text and in the exports.

These items now get a line break, too. In a heading, a caption or a
list item, consecutive `<br>` tags give one line break. In a `<pre>`
block, each `<br>` is a newline. The text of a checkbox stays on one
line. A run that only holds `<br>` tags gives no item of its own.

Signed-off-by: Morten Dæhli Aslesen <morten@lagabote.no>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @morten-lagabote, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 8, 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)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working html issue related to html backend labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 7dff863519. The analysis read the diff only. It did not run code from this pull request.

The PR fixes the HTML backend leaving the internal U+E000 &lt;br&gt; sentinel in text outside paragraphs and table cells. It resolves the sentinel in headings, captions, list items, &lt;pre&gt; blocks, and checkbox text, and adds a focused test for all cases.

CI safety: no concern found. A maintainer must still approve CI.

2 related pull request(s) in the same code
PR State Signal Assessment
#4510 open changes the same code related: PR 4510 fixes trailing text after nested list blocks in the same file and overlaps one hunk in _add_list_item_with_content, but it solves a different problem and the two changes can both be merged.
#4670 open referenced as #4670 related: PR 4670 refactors to_single_text_element() to avoid spreading one run's formatting to a whole heading; this PR changes only the return-value text field of that same method, fixing a different bug, and the PR body confirms the two changes merge without conflict.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Morten Dæhli Aslesen <morten@lagabote.no>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Oct 8, 2026

@dolfim-ibm dolfim-ibm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dolfim-ibm
dolfim-ibm merged commit 7be1913 into docling-project:main Oct 14, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working html issue related to html backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML backend: <br> leaks the internal sentinel U+E000 into list items, headings and captions

3 participants