Skip to content

fix(parser): emit a single structured table item in document order - #18168

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
xugangqiang:fix/html-md-table-single-item
Aug 12, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
xugangqiang:fix/html-md-table-single-item

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

The Go HTML and Markdown parsers emitted every table twice:

  1. an inline doc_type_kwd:"text" item carrying the full <table>…</table>
    markup, mixed into the surrounding prose; and
  2. a structured doc_type_kwd:"table" / ck_type:"table" item that was
    deferred and appended at the end of the stream.

This produced three downstream problems:

  • Duplicate embedding (SE1): the same table was embedded twice, diluting
    retrieve-time ranking of the real chunk.
  • Tag pollution (SE2): the raw <table> markup was injected into the
    neighbouring prose chunk instead of clean text.
  • Relocated table (SE3): the structured item was appended after the walk,
    so the table lost its original document position and the table_context_size
    context window the chunker attaches was computed against the wrong
    neighbourhood.

Fix (Go only — Python untouched)

Keep exactly one structured doc_type_kwd:"table" / ck_type:"table" item
and emit it in its original document order; drop the redundant inline
doc_type_kwd:"text" copy. Concretely:

  • walkHTMLBlocks (top-level tables) and walkHTMLLeaf (nested tables in
    div/section/…) now append the single structured item inline at the
    table's document position instead of deferring a tableItems slice to the
    end.
  • walkMarkdownBlocksWithImages emits the table as one structured item in
    document order (no separate inlined copy, no end-of-walk append).
  • Restored the per-block ck_type mapping (htmlTagToCkType) that the
    duplicate path relied on, and removed the now-dead tableItems deferral.

The downstream chunker still consumes a single doc_type_kwd:"table" item to
keep the table whole as a discrete, independently retrievable chunk
(internal/ingestion/component/chunker/token.go), so its behaviour is
unchanged.

Scope

  • internal/parser/parser/html_parser.go
  • internal/parser/parser/markdown_parser.go
  • parser align / test files

Python side is intentionally not changed.

Test plan

  • New / rewritten unit tests lock the single-item + in-document-order +
    no-inline-copy contract for: top-level table, nested table, nested table
    with surrounding prose (<div><p>before</p><table>…</table><p>after</p></div>),
    markdown table with surrounding prose, multiple tables ordering, and raw
    <table> HTML blocks.
  • Alignment golden tests (TestHTMLParser_AlignmentGolden,
    TestMarkdownParser_AlignmentGolden) keep comparing non-table prose via
    filterTableDivergence, and now additionally assert a table representation
    is present on both sides (hasTableRepresentation) so a silently dropped
    table cannot pass.
  • bash build.sh --test ./internal/parser/parser/... ✅
  • bash build.sh --test ./internal/ingestion/... ✅ (chunker table contract
    unchanged; no ingestion golden exercises the parser table path, so this is
    not a regression surface for the change).

Closes #18157

HTML and Markdown parsers previously emitted every table twice: an inline
doc_type_kwd:"text" copy carrying the full <table> markup (mixed into the
surrounding prose) plus a structured doc_type_kwd:"table" item that was
deferred and appended at the end of the stream. This caused:

- duplicate embedding of the same table (split ranking dilution);
- raw <table> tag pollution of neighbouring prose chunks;
- tables relocated away from their original document position, breaking the
  table_context_size context window the chunker attaches.

Keep exactly ONE structured doc_type_kwd:"table"/ck_type:"table" item,
emitted in its original document order, and drop the redundant inline text
copy. Restore the per-block ck_type mapping (htmlTagToCkType) that the
duplicate path relied on, and remove the now-dead tableItems deferral
plumbing.

Python side is intentionally unchanged.

Closes infiniflow#18157
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 12, 2026
@xugangqiang xugangqiang added the ci Continue Integration label Aug 12, 2026
@xugangqiang xugangqiang self-assigned this Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

HTML and Markdown parsers now emit one structured table item in document order. Surrounding prose no longer contains duplicate table markup. Tests cover top-level, nested, multiple-table, and cross-parser alignment behavior.

Changes

Structured table emission

Layer / File(s) Summary
HTML table flow
internal/parser/parser/html_parser.go, internal/parser/parser/html_parser_align_test.go
HTML traversal emits tables in place, flushes surrounding prose, and validates nested and multiple-table ordering.
Markdown table flow
internal/parser/parser/markdown_parser.go, internal/parser/parser/markdown_parser_test.go
Markdown and raw HTML tables emit one structured item at the source position. Tests validate prose boundaries and table ordering.
Table-aware alignment validation
internal/parser/parser/align_test.go, internal/parser/parser/html_parser_align_test.go, internal/parser/parser/markdown_parser_test.go
Alignment checks filter standalone table differences and compare normalized table representations between Go and Python outputs.

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

Possibly related issues

  • infiniflow/ragflow#18113: The PR addresses duplicate inline and structured table output.

Possibly related PRs

Suggested labels: 🧪 test

Suggested reviewers: yuzhichang, jinhai-cn, yingfeng

Poem

One table hops into its place,
No markup twin leaves a trace.
Prose stays clean, rows stay bright,
Tests confirm the order is right. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main parser change: emitting one structured table item in document order.
Description check ✅ Passed The description follows the required Summary section and provides clear scope, implementation details, rationale, and test results.
Linked Issues check ✅ Passed The changes satisfy issue #18157 by removing duplicate table output, preserving order, cleaning prose, and retaining structured-table chunking.
Out of Scope Changes check ✅ Passed All changes remain within the parser and parser-test scope described by issue #18157; Python and unrelated components are unchanged.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/parser/parser/markdown_parser_test.go (1)

101-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the test for the current contract.

TestMarkdownParser_ParseWithResult_RendersTableInline now verifies structured table output. Rename it to describe structured table emission.

As per coding guidelines, remove stale documentation.

🤖 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/parser/parser/markdown_parser_test.go` around lines 101 - 104,
Rename TestMarkdownParser_ParseWithResult_RendersTableInline to describe
structured table emission, matching its current contract that tables produce one
structured table item. Remove the stale inline documentation that no longer
reflects the test’s intended behavior.

Sources: Coding guidelines, Learnings

🤖 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.

Inline comments:
In `@internal/parser/parser/html_parser_align_test.go`:
- Around line 57-70: Require exactly one structured table item in each
single-table test instead of tracking only a boolean or last index. Update the
checks at internal/parser/parser/html_parser_align_test.go:57-70, :136-149, and
:218-228, plus internal/parser/parser/markdown_parser_test.go:360-364, :415-423,
and :529-534, to count items with doc_type_kwd "table" and fail unless the count
is one; preserve the existing table-content and duplicate-inline-text
assertions.

---

Nitpick comments:
In `@internal/parser/parser/markdown_parser_test.go`:
- Around line 101-104: Rename
TestMarkdownParser_ParseWithResult_RendersTableInline to describe structured
table emission, matching its current contract that tables produce one structured
table item. Remove the stale inline documentation that no longer reflects the
test’s intended behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c5100ff-afca-4cd9-8a15-cfcddd4a2026

📥 Commits

Reviewing files that changed from the base of the PR and between eada2f6 and bdada28.

📒 Files selected for processing (5)
  • internal/parser/parser/align_test.go
  • internal/parser/parser/html_parser.go
  • internal/parser/parser/html_parser_align_test.go
  • internal/parser/parser/markdown_parser.go
  • internal/parser/parser/markdown_parser_test.go

xugangqiang and others added 2 commits August 12, 2026 17:19
…rgence drop

The alignment golden previously compared the inline <table> text item on
both sides, which is what actually guarded against a table being collapsed
or a column dropped. filterTableDivergence (introduced to drop the duplicate
inline copy) removed that comparison entirely, leaving only an existence
check. Restore the equivalence guard:

- tableCellSignature / tableSignatures extract per-table cell text (th/td
  inner text) and compare the DISTINCT table sets between Go and Python.
  Tolerant of serialization differences (attribute order, <tbody> insertion)
  yet sensitive to dropped columns/cells.
- Harden filterTableDivergence: drop an item only when it is ENTIRELY a
  <table> block (isStandaloneTable), so a prose item that merely contains a
  table is never masked.
- Add TestHTMLParser_MultipleTablesOrdering, symmetric to the Markdown
  counterpart, locking multiple top-level tables in document order.

Closes infiniflow#18157
…le test

Add a tableCount assertion to each single-table HTML/Markdown test so the
cardinality of doc_type_kwd:"table" items is locked to exactly one,
strengthening the single-item-in-document-order contract beyond the
boolean/last-index checks.

Co-authored-by: CodeBuddy <[email protected]>

@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.

Actionable comments posted: 4

🤖 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.

Inline comments:
In `@internal/parser/parser/align_test.go`:
- Around line 390-425: Update tableSignatures and assertTablesEquivalent to
preserve table occurrence counts and document order instead of storing
signatures in a map/set. Normalize known duplicate representations while
retaining one entry per source table, then compare the ordered occurrence lists
so missing or extra identical tables fail the equivalence check and exactly one
structured item is required per table.
- Around line 340-342: Replace the LastIndex-based table detection in the helper
used by filterTableDivergence with nesting-aware boundary tracking. Match the
closing tag for the first top-level table, reject any second top-level table or
non-whitespace content after that boundary, and continue accepting nested tables
within the first element.

In `@internal/parser/parser/html_parser_align_test.go`:
- Around line 255-260: Update the comment above
TestHTMLParser_MultipleTablesOrdering to describe only the current ordering and
table-emission contract; remove the parenthetical reference to the old
deferred-append behavior and migration history.
- Around line 285-322: Strengthen the assertions around the table items in the
test’s result scan: track whether inline table markup appears in any
doc_type_kwd="text" item, reject such markup, and require each collected table
item to have ck_type="table". Preserve the existing count, ordering, and
cell-content checks while validating both table entries completely.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a139ff62-ac7d-4d4a-92f0-9906399d0ba0

📥 Commits

Reviewing files that changed from the base of the PR and between bdada28 and 3bd730c.

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

Comment on lines +340 to +342
close := strings.ToLower(t)
idx := strings.LastIndex(close, "</table>")
return idx >= 0 && strings.TrimSpace(t[idx+len("</table>"):]) == ""

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Detect exactly one table element.

strings.LastIndex accepts text such as "<table>...</table> prose <table>...</table>" as a standalone table. filterTableDivergence then removes the prose item, despite Lines 304-310 requiring surrounding prose to remain in the alignment comparison.

Use nesting-aware table-boundary detection. Reject text that contains a second top-level table or non-whitespace content after the matching closing tag.

🤖 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/parser/parser/align_test.go` around lines 340 - 342, Replace the
LastIndex-based table detection in the helper used by filterTableDivergence with
nesting-aware boundary tracking. Match the closing tag for the first top-level
table, reject any second top-level table or non-whitespace content after that
boundary, and continue accepting nested tables within the first element.

Comment on lines +390 to +425
func tableSignatures(items []map[string]any) map[string]bool {
sigs := map[string]bool{}
for _, it := range items {
kd, _ := it["doc_type_kwd"].(string)
text, _ := it["text"].(string)
if kd != "table" && !isStandaloneTable(text) {
continue
}
if sig := tableCellSignature(text); sig != "" {
sigs[sig] = true
}
}
return sigs
}

// assertTablesEquivalent fails the test if the set of tables (by cell-content
// signature) differs between the Go output and the Python golden. This restores
// the Go↔Python table-equivalence guard that filterTableDivergence intentionally
// removes from the prose comparison: it catches a table being collapsed or a
// column/cell dropped on either side, while tolerating serialization
// differences (attribute order, <tbody> insertion).
func assertTablesEquivalent(t *testing.T, goItems, pyItems []map[string]any) {
t.Helper()
goSigs := tableSignatures(goItems)
pySigs := tableSignatures(pyItems)
for sig := range goSigs {
if !pySigs[sig] {
t.Errorf("Go table not present in Python golden (possible collapse / dropped column):\n%s", sig)
}
}
for sig := range pySigs {
if !goSigs[sig] {
t.Errorf("Python golden table not present in Go output (possible collapse / dropped column):\n%s", sig)
}
}
}

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Preserve repeated-table cardinality in the equivalence check.

tableSignatures collapses equal signatures into a set. If a document has two identical tables and the Go parser emits only one, both sides produce the same set and assertTablesEquivalent passes. The prose filter has already removed the Python table items.

Normalize known duplicate representations, but retain each source table occurrence and its document order when comparing tables. The PR requires exactly one structured item per table.

🤖 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/parser/parser/align_test.go` around lines 390 - 425, Update
tableSignatures and assertTablesEquivalent to preserve table occurrence counts
and document order instead of storing signatures in a map/set. Normalize known
duplicate representations while retaining one entry per source table, then
compare the ordered occurrence lists so missing or extra identical tables fail
the equivalence check and exactly one structured item is required per table.

Comment on lines +255 to +260
// TestHTMLParser_MultipleTablesOrdering is the HTML counterpart of
// TestMarkdownParser_MultipleTablesOrdering: two top-level tables must each be
// emitted as a SINGLE structured doc_type_kwd:"table" item, in document order,
// bracketing the "Middle." paragraph (not relocated to the end of the stream —
// the old deferred-append behaviour this PR removes). Cell text of both tables
// must be present and in source order.

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove migration-history text from the test comment.

Lines 258-260 describe the removed deferred-append implementation. Keep the comment limited to the current ordering contract.

As per coding guidelines, “keep package and doc comments aligned with the current runtime path rather than migration history.”

Proposed fix
 // TestHTMLParser_MultipleTablesOrdering is the HTML counterpart of
 // TestMarkdownParser_MultipleTablesOrdering: two top-level tables must each be
 // emitted as a SINGLE structured doc_type_kwd:"table" item, in document order,
-// bracketing the "Middle." paragraph (not relocated to the end of the stream —
-// the old deferred-append behaviour this PR removes). Cell text of both tables
-// must be present and in source order.
+// bracketing the "Middle." paragraph. Cell text of both tables must be present
+// and in source order.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TestHTMLParser_MultipleTablesOrdering is the HTML counterpart of
// TestMarkdownParser_MultipleTablesOrdering: two top-level tables must each be
// emitted as a SINGLE structured doc_type_kwd:"table" item, in document order,
// bracketing the "Middle." paragraph (not relocated to the end of the stream —
// the old deferred-append behaviour this PR removes). Cell text of both tables
// must be present and in source order.
// TestHTMLParser_MultipleTablesOrdering is the HTML counterpart of
// TestMarkdownParser_MultipleTablesOrdering: two top-level tables must each be
// emitted as a SINGLE structured doc_type_kwd:"table" item, in document order,
// bracketing the "Middle." paragraph. Cell text of both tables must be present
// and in source order.
🤖 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/parser/parser/html_parser_align_test.go` around lines 255 - 260,
Update the comment above TestHTMLParser_MultipleTablesOrdering to describe only
the current ordering and table-emission contract; remove the parenthetical
reference to the old deferred-append behavior and migration history.

Source: Coding guidelines

Comment on lines +285 to 322
for i, it := range res.JSON {
text, _ := it["text"].(string)
switch it["doc_type_kwd"] {
case "text":
switch text {
case "Title":
titleIdx = i
case "Middle.":
middleIdx = i
case "End.":
endIdx = i
}
case "table":
tableItemIdx = append(tableItemIdx, i)
default:
t.Fatalf("unexpected doc_type_kwd %q", it["doc_type_kwd"])
}
}

if titleIdx < 0 || middleIdx < 0 || endIdx < 0 {
t.Fatalf("missing anchor text item (title=%d middle=%d end=%d)", titleIdx, middleIdx, endIdx)
}
if len(tableItemIdx) != 2 {
t.Fatalf("table items = %d, want 2", len(tableItemIdx))
}
// Both tables appear in document order, bracketing "Middle.":
// table1 before Middle, table2 between Middle and End.
if !(titleIdx < tableItemIdx[0] && tableItemIdx[0] < middleIdx && middleIdx < tableItemIdx[1] && tableItemIdx[1] < endIdx) {
t.Fatalf("table order wrong: tables=%v title=%d middle=%d end=%d", tableItemIdx, titleIdx, middleIdx, endIdx)
}
t1, _ := res.JSON[tableItemIdx[0]]["text"].(string)
t2, _ := res.JSON[tableItemIdx[1]]["text"].(string)
if !strings.Contains(t1, "x") || !strings.Contains(t1, "y") {
t.Errorf("first table item missing x/y cells: %q", t1)
}
if !strings.Contains(t2, "p") || !strings.Contains(t2, "q") {
t.Errorf("second table item missing p/q cells: %q", t2)
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Verify the complete contract for both table items.

This test checks table count and order, but it passes if either table lacks ck_type:"table" or if table markup is also emitted in a doc_type_kwd:"text" item. Track inline table markup and validate ck_type for each table item.

Proposed fix
 	var tableItemIdx []int
 	titleIdx, middleIdx, endIdx := -1, -1, -1
+	inlineTableCount := 0
 	for i, it := range res.JSON {
 		text, _ := it["text"].(string)
 		switch it["doc_type_kwd"] {
 		case "text":
+			if strings.Contains(text, "<table") {
+				inlineTableCount++
+			}
 			switch text {
@@
 		case "table":
+			if got := it["ck_type"]; got != "table" {
+				t.Errorf("table item ck_type = %v, want table", got)
+			}
 			tableItemIdx = append(tableItemIdx, i)
@@
 	if len(tableItemIdx) != 2 {
 		t.Fatalf("table items = %d, want 2", len(tableItemIdx))
 	}
+	if inlineTableCount != 0 {
+		t.Errorf("found %d text item(s) containing <table> markup", inlineTableCount)
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for i, it := range res.JSON {
text, _ := it["text"].(string)
switch it["doc_type_kwd"] {
case "text":
switch text {
case "Title":
titleIdx = i
case "Middle.":
middleIdx = i
case "End.":
endIdx = i
}
case "table":
tableItemIdx = append(tableItemIdx, i)
default:
t.Fatalf("unexpected doc_type_kwd %q", it["doc_type_kwd"])
}
}
if titleIdx < 0 || middleIdx < 0 || endIdx < 0 {
t.Fatalf("missing anchor text item (title=%d middle=%d end=%d)", titleIdx, middleIdx, endIdx)
}
if len(tableItemIdx) != 2 {
t.Fatalf("table items = %d, want 2", len(tableItemIdx))
}
// Both tables appear in document order, bracketing "Middle.":
// table1 before Middle, table2 between Middle and End.
if !(titleIdx < tableItemIdx[0] && tableItemIdx[0] < middleIdx && middleIdx < tableItemIdx[1] && tableItemIdx[1] < endIdx) {
t.Fatalf("table order wrong: tables=%v title=%d middle=%d end=%d", tableItemIdx, titleIdx, middleIdx, endIdx)
}
t1, _ := res.JSON[tableItemIdx[0]]["text"].(string)
t2, _ := res.JSON[tableItemIdx[1]]["text"].(string)
if !strings.Contains(t1, "x") || !strings.Contains(t1, "y") {
t.Errorf("first table item missing x/y cells: %q", t1)
}
if !strings.Contains(t2, "p") || !strings.Contains(t2, "q") {
t.Errorf("second table item missing p/q cells: %q", t2)
}
var tableItemIdx []int
titleIdx, middleIdx, endIdx := -1, -1, -1
inlineTableCount := 0
for i, it := range res.JSON {
text, _ := it["text"].(string)
switch it["doc_type_kwd"] {
case "text":
if strings.Contains(text, "<table") {
inlineTableCount++
}
switch text {
case "Title":
titleIdx = i
case "Middle.":
middleIdx = i
case "End.":
endIdx = i
}
case "table":
if got := it["ck_type"]; got != "table" {
t.Errorf("table item ck_type = %v, want table", got)
}
tableItemIdx = append(tableItemIdx, i)
default:
t.Fatalf("unexpected doc_type_kwd %q", it["doc_type_kwd"])
}
}
if titleIdx < 0 || middleIdx < 0 || endIdx < 0 {
t.Fatalf("missing anchor text item (title=%d middle=%d end=%d)", titleIdx, middleIdx, endIdx)
}
if len(tableItemIdx) != 2 {
t.Fatalf("table items = %d, want 2", len(tableItemIdx))
}
if inlineTableCount != 0 {
t.Errorf("found %d text item(s) containing <table> markup", inlineTableCount)
}
// Both tables appear in document order, bracketing "Middle.":
// table1 before Middle, table2 between Middle and End.
if !(titleIdx < tableItemIdx[0] && tableItemIdx[0] < middleIdx && middleIdx < tableItemIdx[1] && tableItemIdx[1] < endIdx) {
t.Fatalf("table order wrong: tables=%v title=%d middle=%d end=%d", tableItemIdx, titleIdx, middleIdx, endIdx)
}
t1, _ := res.JSON[tableItemIdx[0]]["text"].(string)
t2, _ := res.JSON[tableItemIdx[1]]["text"].(string)
if !strings.Contains(t1, "x") || !strings.Contains(t1, "y") {
t.Errorf("first table item missing x/y cells: %q", t1)
}
if !strings.Contains(t2, "p") || !strings.Contains(t2, "q") {
t.Errorf("second table item missing p/q cells: %q", t2)
}
🤖 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/parser/parser/html_parser_align_test.go` around lines 285 - 322,
Strengthen the assertions around the table items in the test’s result scan:
track whether inline table markup appears in any doc_type_kwd="text" item,
reject such markup, and require each collected table item to have
ck_type="table". Preserve the existing count, ordering, and cell-content checks
while validating both table entries completely.

@yuzhichang
yuzhichang merged commit 8c5c870 into infiniflow:main Aug 12, 2026
3 checks passed
@xugangqiang
xugangqiang deleted the fix/html-md-table-single-item branch August 12, 2026 10:59
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML/Markdown parser emits duplicate table representation; keep a single structured doc_type_kwd:"table" item in document order

2 participants