fix(docparser): normalize PaddleOCR-VL HTML tables (#1725)

PaddleOCR-VL renders tables as HTML with per-cell text-align styles.
These waste tokens on layout markup and bypass the chunker's
table-protection logic (which only recognizes Markdown pipe tables),
causing large tables to be split mid-row.

Convert inline HTML <table> blocks to GFM Markdown tables when possible,
and strip presentational attributes (style/class/align/...) for tables
using rowspan/colspan that Markdown cannot express.

Refs: https://github.com/Tencent/WeKnora/issues/1725
This commit is contained in:
wizardchen
2026-06-22 17:28:17 +08:00
committed by lyingbug
parent abf6a99b90
commit 74c845a1f4
3 changed files with 149 additions and 0 deletions
@@ -58,6 +58,12 @@ func (c *PaddleOCRVLReader) Read(ctx context.Context, req *types.ReadRequest) (*
return nil, fmt.Errorf("PaddleOCR-VL layout-parsing: %w", err)
}
// PaddleOCR-VL renders tables as styled HTML (per-cell text-align), which
// wastes tokens and defeats the chunker's table-protection logic. Convert
// them to Markdown tables (or strip layout attributes when conversion is
// not possible) before downstream processing.
mdContent = normalizeHTMLTables(mdContent)
imageRefs, mdContent := c.processImages(mdContent, imagesB64)
mdContent, imageRefs = ensureOriginalImageRef(req, mdContent, imageRefs)