Skip to content

refactor(parser): preserve HTML <table> structure (inline + structured item) - #18101

Closed
xugangqiang wants to merge 2 commits into
fix/parser-align-foundationfrom
fix/html-table-structure
Closed

xugangqiang wants to merge 2 commits into
fix/parser-align-foundationfrom
fix/html-table-structure

Conversation

@xugangqiang

@xugangqiang xugangqiang commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stop flattening <table> into a single text blob. A <table> now emits:

  1. an inlined doc_type_kwd:"text" item keeping the <table>…</table> markup
    (row/column structure survives for embedding/retrieval/LLM rendering), and
  2. a structured doc_type_kwd:"table" / ck_type:"table" item appended after
    the walk, consumed by the downstream chunker.

Covers both top-level tables (walkHTMLBlocks) and tables nested in
div/section/article (via walkHTMLLeaf). Mirrors markdown_parser.go's
two-item table handling (inline text copy + appended doc_type_kwd:"table"
item). It matches Python's RAGFlowHtmlParser only in keeping the raw
<table>…</table> markup: Python keeps the table once, outside the inline
flow, and adds doc_type_kwd/ck_type downstream — this change emits both
items at the parser layer.

Test plan

  • TestHTMLParser_TableProducesStructuredItems
  • TestHTMLParser_NestedTableProducesStructuredItems
  • TestHTMLParser_NestedListItemsPreserved
  • TestHTMLParser_PrePreservesVerbatim
  • TestHTMLParser_AlignmentGolden (compares vs html.python.golden.json,
    ignores "table" via meta.accepted_divergences)

Dependency

Stacks on #18014 (framework in main) and the foundation helpers PR
(fix/parser-align-foundation).

Note

This change was not described in the original combined PR's title; called out
here for explicit review.

Related

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03473bd0-5ebe-4d54-be4d-211b1e247f18

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

…d item)

Stop flattening <table> into a single text blob. A <table> now emits:
1. an inlined doc_type_kwd:"text" item keeping the <table>...</table> markup
   (row/column structure survives for embedding/retrieval/LLM rendering), and
2. a structured doc_type_kwd:"table" / ck_type:"table" item appended after
   the walk, consumed by the downstream chunker.

Covers both top-level tables (walkHTMLBlocks) and tables nested in
div/section/article (via walkHTMLLeaf). Mirrors markdown_parser.go table
handling and Python's RAGFlowHtmlParser.

Tests:
- TestHTMLParser_TableProducesStructuredItems
- TestHTMLParser_NestedTableProducesStructuredItems
- TestHTMLParser_NestedListItemsPreserved
- TestHTMLParser_PrePreservesVerbatim
- TestHTMLParser_AlignmentGolden (compares vs html.python.golden.json, ignores
  "table" via meta.accepted_divergences)

Depends on #18014 and the foundation helpers PR (align_test.go).

Files:
  internal/parser/parser/html_parser.go
  internal/parser/parser/html_parser_align_test.go (new)
  internal/parser/parser/testdata/html.python.golden.json (new)
  internal/parser/parser/testdata/html.sample.html (new)
@xugangqiang
xugangqiang force-pushed the fix/html-table-structure branch from 498dbb6 to b3f9bed Compare August 11, 2026 09:21
renderTableHTML only fails on unsupported node kinds, which a parsed
<table> never triggers, so the degenerate flatten-children branch in
walkHTMLLeaf is unreachable. Remove it so the nested-table path matches
the top-level walkHTMLBlocks case (both skip silently when the markup is
empty).

Also tighten the inaccurate 'mirrors Python's HtmlParser' inline comment
in the same block (the two-item split is the markdown_parser.go model;
Python keeps the table once, outside the inline flow).
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 11, 2026
@yingfeng
yingfeng deleted the branch fix/parser-align-foundation August 11, 2026 11:02
@yingfeng yingfeng closed this Aug 11, 2026
@yingfeng
yingfeng deleted the fix/html-table-structure branch August 19, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants