Skip to content

fix(parser): start a new line before every HTML block element - #21107

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
L4XB:fix/html-block-boundaries
Oct 20, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
L4XB:fix/html-block-boundaries

Conversation

@L4XB

@L4XB L4XB commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

walkHTMLLeaf in html_parser.go handles line breaks around block children unevenly:

  • After a block child, it breaks the line for every tag in isBlockTag.
  • Before a block child, it breaks only for p, li, h1–h6, tr and blockquote.

So text in front of a nested div, section, article, header or footer ran into the block's own text. Block elements that isBlockTag does not list got no break on either side. On main:

HTML text item
<div>Name:<div>Alice</div></div> Name:Alice
<div><span>Total</span><div>42</div></div> Total42
<div>A<dl><dt>Term</dt><dd>Definition</dd></dl>B</div> ATermDefinitionB
<div>See<figure><figcaption>Fig 1</figcaption></figure>below</div> SeeFig 1below
<div>above<hr>below</div> abovebelow
<article>left<nav>Menu</nav>right</article> leftMenuright

The glued tokens (Name:Alice, Total42) match a search for neither word.

What changed

  • The break in front of a block child now checks isBlockTag, the same as the break after it. htmlBodyToText, the email body walker, already does both, and TestHTMLBodyToText covers its "text before nested block" case.
  • isBlockTag now lists the elements HTML lays out as blocks: main, nav, aside, address, hgroup, search, center, ul, ol, menu, dl, dt, dd, figure, figcaption, details, summary, dialog, form, fieldset, legend and hr.

The email walker shares isBlockTag, so definition lists and rules in email bodies are separated as well. Inline elements are unchanged: <div>Hello <b>bold</b> and <a>link</a> text</div> is still one line.

Testing

  • TestHTMLParser_BlockElementsStartANewLine covers the six cases in the table plus one inline case. On main, all six block cases fail.
  • TestHTMLBodyToText gets a definition list and rule case, which also fails on main.
  • The existing HTML tests, including TestHTMLParser_AlignmentGolden, and the email tests pass unchanged.
CGO_ENABLED=0 go test ./internal/parser/... -count=1   # ok
gofmt -l internal/parser/parser/                       # nothing

go vet reports only the existing paddleocr.go:453 context warning.

walkHTMLLeaf broke the line in front of a block child only for p, li,
headings, tr and blockquote, while it broke the line after every tag in
isBlockTag. Text in front of a nested div, section or article ran into the
block's own ("<div>Name:<div>Alice</div></div>" read "Name:Alice").
Block elements missing from isBlockTag (dl, dt, dd, figure, figcaption,
hr, nav, main, aside, ...) broke it on neither side, so "A<dl><dt>Term"
read "ATerm" and "above<hr>below" read "abovebelow".

The break in front of a block now uses isBlockTag, like the break after it
and like the email body walker, and isBlockTag lists the elements HTML lays
out as blocks. The email walker shares isBlockTag, so its definition lists
and rules are separated too.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8d0a426e-56f3-4fd7-8f5d-bcac3fd91a1e
📥 Commits

Reviewing files that changed from the base of the PR and between 543e167 and 6fee83b.

📒 Files selected for processing: 3
  • internal/parser/parser/email_parser_test.go
  • internal/parser/parser/html_parser.go
  • internal/parser/parser/html_parser_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The HTML parser recognizes additional block elements and inserts line breaks before them when buffered text has no trailing newline. Tests cover flattened output for block and inline elements, including definition lists and horizontal rules.

Changes: HTML block boundaries

Layer / File(s) Summary
Block tag recognition and line breaks
internal/parser/parser/html_parser.go, internal/parser/parser/html_parser_test.go, internal/parser/parser/email_parser_test.go
The parser adds structural, list, grouping, and form tags to isBlockTag. It applies the pre-child line-break rule to all recognized block tags. Tests check line breaks around block elements and unchanged inline text, and verify definition-list and horizontal-rule flattening.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: xugangqiang

Merge Risk: ⚪ Minimal · up to 6fee8

No actionable issue remains from this review; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: adding line breaks before HTML block elements.
Description check Passed The description includes the required Summary section and provides clear background, implementation details, affected behavior, test coverage, and validation results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the tags in line,
And gives each block a break.
The terms and figures find their place,
While rules leave no text wake.
Inline words stay side by side,
Tests trace each newline made.

Comment @coderabbitai help to get the list of available commands.

@jay77721 jay77721 added the ci Continue Integration label Oct 19, 2026
@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@yuzhichang yuzhichang 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. Extending isBlockTag to the remaining block-level elements is consistent with the existing before/after break logic, and the tests cover div, dl, figure, hr, and nav. No blocking findings.

@jay77721
jay77721 requested a review from yuzhichang October 20, 2026 01:47
@yuzhichang
yuzhichang merged commit 781397b into infiniflow:main Oct 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants