From 33549d90e965730eeeb555bed01a7554a9c3ce13 Mon Sep 17 00:00:00 2001 From: xugangqiang Date: Tue, 11 Aug 2026 17:31:05 +0800 Subject: [PATCH] refactor(parser): drop unreachable fallback in walkHTMLLeaf table case renderTableHTML only fails on unsupported node kinds, which a parsed 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). --- internal/parser/parser/html_parser.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/parser/parser/html_parser.go b/internal/parser/parser/html_parser.go index 3704f0b9da..9feb8438b6 100644 --- a/internal/parser/parser/html_parser.go +++ b/internal/parser/parser/html_parser.go @@ -324,11 +324,11 @@ func walkHTMLLeaf(n *html.Node, w *leafWriter, tableItems *[]map[string]any) { // Keep the table as its full HTML markup (NOT flattened) so // row/column structure survives into the wrapper's text item, // embedding, retrieval, and LLM rendering. This mirrors the - // top-level walkHTMLBlocks "table" case and Python's HtmlParser, - // and covers tables nested in div/section/article/… (which the - // walkHTMLBlocks case never reaches). The structured table item - // is collected for the downstream chunker (appended after the - // walk by the caller, same as the top-level path). + // top-level walkHTMLBlocks "table" case, and covers tables nested + // in div/section/article/… (which the walkHTMLBlocks case never + // reaches). The structured table item is collected for the + // downstream chunker (appended after the walk by the caller, same + // as the top-level path). markup := renderTableHTML(n) if strings.TrimSpace(markup) != "" { w.writeText(markup) @@ -337,12 +337,6 @@ func walkHTMLLeaf(n *html.Node, w *leafWriter, tableItems *[]map[string]any) { "doc_type_kwd": "table", "ck_type": "table", }) - } else { - // Degenerate: render failed; flatten children without markup - // so we never drop the cell text entirely. - for child := n.FirstChild; child != nil; child = child.NextSibling { - walkHTMLLeaf(child, w, tableItems) - } } return }