Skip to content

fix(parser): preserve loose body text in HTMLParser - #17290

Merged
xugangqiang merged 2 commits into
infiniflow:mainfrom
WOLIKIMCHENG:fix/17278-html-loose-text
Jul 24, 2026
Merged

xugangqiang merged 2 commits into
infiniflow:mainfrom
WOLIKIMCHENG:fix/17278-html-loose-text

Conversation

@WOLIKIMCHENG

@WOLIKIMCHENG WOLIKIMCHENG commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #17278.

The Go HTMLParser now preserves non-empty loose text that appears directly under the parsed body, including preamble, between-block, and trailing text, instead of dropping it while walking block elements.

It continues to skip head metadata and script/style/noscript content, including nested script/style/noscript subtrees.

Tests:

  • bash build.sh --test -run 'TestHTMLParser_ParseWithResult|TestWalkHTMLBlocks' ./internal/parser/parser
  • bash build.sh --test ./internal/parser/parser
  • git diff --check -- internal/parser/parser/html_parser.go internal/parser/parser/parse_with_result_test.go

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eb644391-682f-41aa-a556-034c7350b6e1

📥 Commits

Reviewing files that changed from the base of the PR and between 5dba9b5 and 2c4a1dc.

📒 Files selected for processing (1)
  • internal/parser/parser/html_parser.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/parser/parser/html_parser.go

📝 Walkthrough

Walkthrough

The HTML parser now preserves eligible loose text, skips head metadata, centralizes text-item creation, and excludes noscript content alongside script and style subtrees. Tests cover wrapper text, omitted body elements, head text, and hidden content.

Changes

HTML parser behavior

Layer / File(s) Summary
Loose-text traversal and emission
internal/parser/parser/html_parser.go, internal/parser/parser/parse_with_result_test.go
walkHTMLBlocks emits normalized loose-text items under body content, traverses html/body wrappers, skips head content, and tests text preservation and type mappings.
Hidden subtree filtering
internal/parser/parser/html_parser.go, internal/parser/parser/parse_with_result_test.go
Leaf collection skips noscript alongside script and style, with tests confirming hidden content is absent from output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: 🧪 test

Suggested reviewers: xugangqiang

Poem

I’m a rabbit with HTML in my den,
Loose text now hops safely in.
Head notes hide, scripts fade away,
Noscript joins them out of play.
Clean blocks march in a tidy row—
Parsing blooms where carrots grow! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preserving loose HTML body text in HTMLParser.
Description check ✅ Passed The description includes the required Summary and gives purpose, scope, and test notes.
Linked Issues check ✅ Passed The changes address #17278 by preserving loose body text and keeping head/script/style/noscript excluded.
Out of Scope Changes check ✅ Passed The PR stays within parser behavior and tests, with no clear unrelated code changes.

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

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

@yingfeng
yingfeng requested a review from xugangqiang July 23, 2026 11:38
@yingfeng yingfeng added the ci Continue Integration label Jul 23, 2026
@xugangqiang
xugangqiang merged commit 008fa3e into infiniflow:main Jul 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go: HTMLParser silently drops top-level loose text (preamble / between / trailing blocks)

3 participants