Skip to content

Go: parse HTML file - #16018

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix461
Jun 15, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix461

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(api/default)> parse file 'test.html';
Parsing HTML file: test.html
  <html>
......

Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds HTML file parsing to the Go ingestion pipeline. A new FileTypeHTML constant and extension mappings (html, htm) are added to utility/file.go. A new HTMLParser struct is introduced with an iterative DOM traversal method. The parser registry in type.go is updated to dispatch FileTypeHTML to the new parser.

Changes

HTML Parser Support

Layer / File(s) Summary
FileTypeHTML constant and extension detection
internal/utility/file.go
Adds the exported FileTypeHTML = "html" constant to the FileType enum and maps the "html" and "htm" extensions to it in GetFileType.
HTMLParser struct, constructor, parse dispatch, and DOM traversal
internal/ingestion/parser/html_parser.go
Defines the HTMLParser struct with the Official libType constant, NewHTMLParser constructor with validation, Parse dispatch method, OfficialHTMLParse that calls html.Parse (discarding parse errors), WalkIterative for depth-tracked pre-order DOM traversal (printing tags, text, comments, and doctypes), and a String() identifier method.
GetParser wired for FileTypeHTML
internal/ingestion/parser/type.go
Adds a case utility.FileTypeHTML branch in GetParser that constructs and returns a NewHTMLParser(Official) instance.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant GetParser
  participant NewHTMLParser
  participant HTMLParser
  participant html.Parse
  participant WalkIterative

  Caller->>GetParser: GetParser(fileType, config)
  GetParser->>NewHTMLParser: NewHTMLParser("official")
  NewHTMLParser-->>GetParser: *HTMLParser
  GetParser-->>Caller: Parser interface
  Caller->>HTMLParser: Parse(filename, data)
  HTMLParser->>html.Parse: OfficialHTMLParse(data)
  html.Parse-->>HTMLParser: root *html.Node
  HTMLParser->>WalkIterative: WalkIterative(root)
  WalkIterative-->>HTMLParser: node output printed
  HTMLParser-->>Caller: nil
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, through the DOM I go,
Tags and text in pre-order flow,
html and htm both I know,
Official parsing, stack in tow—
The rabbit parsed HTML, just so!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete. It demonstrates a use case but omits the required template structure, particularly the 'Type of change' section with checkboxes. Complete the PR description using the provided template by adding the 'Type of change' section and clarifying which type of change this PR represents (e.g., New Feature).
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding HTML file parsing functionality to the Go codebase.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@JinHai-CN
JinHai-CN marked this pull request as ready for review June 15, 2026 07:11
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 15, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/ingestion/parser/html_parser.go (1)

106-112: ⚡ Quick win

Avoid O(n²) child reversal in iterative traversal.

Line 108 prepends into a slice for each child, which is quadratic for nodes with many siblings. Push children by iterating from LastChild to PrevSibling and append directly.

Proposed refactor
-		var children []*html.Node
-		for child := current.node.FirstChild; child != nil; child = child.NextSibling {
-			children = append([]*html.Node{child}, children...) // Reverse order
-		}
-		for _, child := range children {
-			stack = append(stack, item{child, current.depth + 1})
-		}
+		for child := current.node.LastChild; child != nil; child = child.PrevSibling {
+			stack = append(stack, item{child, current.depth + 1})
+		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/parser/html_parser.go` around lines 106 - 112, The current
code uses prepend operations (line 108: children = append([]*html.Node{child},
children...)) which creates O(n²) complexity for nodes with many siblings
because each prepend requires copying the entire slice. Instead of iterating
from FirstChild to NextSibling and prepending, iterate backwards from LastChild
to PrevSibling and append directly to the children slice. This achieves the same
reversal of child order while maintaining O(n) linear time complexity. Replace
the forward iteration loop with a backward iteration that uses LastChild and
PrevSibling, and change the append operation from prepend to a regular append.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/ingestion/parser/html_parser.go`:
- Around line 106-112: The current code uses prepend operations (line 108:
children = append([]*html.Node{child}, children...)) which creates O(n²)
complexity for nodes with many siblings because each prepend requires copying
the entire slice. Instead of iterating from FirstChild to NextSibling and
prepending, iterate backwards from LastChild to PrevSibling and append directly
to the children slice. This achieves the same reversal of child order while
maintaining O(n) linear time complexity. Replace the forward iteration loop with
a backward iteration that uses LastChild and PrevSibling, and change the append
operation from prepend to a regular append.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eb817375-2cd9-49ac-aa69-90e6e89e60f4

📥 Commits

Reviewing files that changed from the base of the PR and between 2846216 and ec8b8e1.

📒 Files selected for processing (3)
  • internal/ingestion/parser/html_parser.go
  • internal/ingestion/parser/type.go
  • internal/utility/file.go

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (2846216) to head (ec8b8e1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16018   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit e3cb86d into infiniflow:main Jun 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant