Skip to content

Porting change from #17477 python to go, parse table into chunk for markdown file - #17488

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-parse-table-in-md
Jul 29, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-parse-table-in-md

Conversation

@wangq8

@wangq8 wangq8 commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Porting change from #17477 python to go, parse table into chunk for markdown file
Before:
image

After:
image

@wangq8 wangq8 added the ci Continue Integration label Jul 28, 2026
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Markdown parser now detects inline tables outside fenced code blocks, renders them as HTML, and returns the transformed text through ParseWithResult. A test verifies rendered table elements, removal of raw syntax, and preservation of trailing text.

Changes

Markdown table rendering

Layer / File(s) Summary
Table detection and rendering
internal/parser/parser/markdown_parser.go
Adds fenced-code tracking, table row and separator detection, cell extraction, and HTML rendering using the configured Markdown parser.
Parse result integration and validation
internal/parser/parser/markdown_parser.go, internal/parser/parser/markdown_parser_test.go
ParseWithResult returns rendered text when tables are transformed, while tests verify HTML output and trailing content boundaries.

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

Possibly related PRs

Suggested labels: 🐞 bug

Suggested reviewers: xugangqiang, jinhai-cn

Poem

I tucked a table in HTML bright,
Past fenced code through the night.
Rows became a tidy display,
Raw pipes hopped away.
“Parse it clean!” I thump with glee.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is relevant but missing the required Summary section and background context from the template. Add a ### Summary section that explains the problem, the porting goal, and any key implementation details or validation notes.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title matches the main change: porting table chunk parsing from Python to Go for Markdown files.

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: 2

🤖 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/markdown_parser.go`:
- Around line 99-106: Remove the early return around renderMarkdownTablesInline
in the markdown parsing flow and integrate rendered table content into the
existing walkMarkdownBlocksWithImages result-construction path. Preserve image
extraction, doc_type_kwd image entries, and existing block metadata when
documents contain both tables and images.
- Around line 144-170: Update the fence-closing logic in the markdown parsing
loop around markdownFenceMarker so a matching fence exits only when the marker’s
trailing content is whitespace-only; markers such as ```not-a-closer must keep
the parser inside the fence. Add a regression test in the parser package
covering table-shaped content after such an invalid closer, and validate with
the package-scoped build.sh test command.
🪄 Autofix (Beta)

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: 5b94c464-358f-43fa-822f-11d7a32a9a22

📥 Commits

Reviewing files that changed from the base of the PR and between b4170d0 and 8fba195.

📒 Files selected for processing (2)
  • internal/parser/parser/markdown_parser.go
  • internal/parser/parser/markdown_parser_test.go

Comment on lines +99 to +106
if rendered, ok := renderMarkdownTablesInline(rawText); ok {
return ParseResult{
OutputFormat: "json",
File: map[string]any{
"name": filename,
},
JSON: []map[string]any{{"text": rendered, "doc_type_kwd": "text"}},
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve block and image extraction when a table is present.

This early return bypasses walkMarkdownBlocksWithImages at Line 112 for the entire document. Files containing both a table and an image therefore lose image resolution/doc_type_kwd: "image" output, and all existing block metadata is collapsed into one text item. Render table blocks without skipping the established result-construction path.

🤖 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.go` around lines 99 - 106, Remove the
early return around renderMarkdownTablesInline in the markdown parsing flow and
integrate rendered table content into the existing walkMarkdownBlocksWithImages
result-construction path. Preserve image extraction, doc_type_kwd image entries,
and existing block metadata when documents contain both tables and images.

Comment on lines +144 to +170
for i := 0; i < len(lines); {
line := strings.TrimRight(lines[i], "\n")
if ch, n, ok := markdownFenceMarker(line); ok {
if inFence && ch == fenceChar && n >= fenceLen {
inFence = false
} else if !inFence {
inFence = true
fenceChar = ch
fenceLen = n
}
buf.WriteString(lines[i])
i++
continue
}
if !inFence && i+1 < len(lines) && isMarkdownTableRow(line) && isMarkdownTableSeparator(strings.TrimRight(lines[i+1], "\n")) {
start := i
i += 2
for i < len(lines) && isMarkdownTableRow(strings.TrimRight(lines[i], "\n")) {
i++
}
for i < len(lines) && strings.TrimSpace(lines[i]) == "" {
i++
}
tableHTML := markdownlib.ToHTML([]byte(strings.Join(lines[start:i], "")), markdownNew(), nil)
buf.WriteString(strings.TrimRight(string(tableHTML), "\r\n"))
buf.WriteByte('\n')
changed = true

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 | ⚡ Quick win

Do not treat invalid fence closers as code-block exits.

Line 147 closes a fence even when the marker has trailing content, such as ```not-a-closer. That line remains inside the fenced block, but subsequent table-shaped code is rendered as HTML at Line 158. Only close a fence when its suffix is whitespace-only, and add a regression case.

Proposed fix
 if ch, n, ok := markdownFenceMarker(line); ok {
-	if inFence && ch == fenceChar && n >= fenceLen {
+	trimmed := strings.TrimLeft(line, " \t")
+	isClosingFence := inFence && ch == fenceChar && n >= fenceLen &&
+		strings.TrimSpace(trimmed[n:]) == ""
+	if isClosingFence {
 		inFence = false
 	} else if !inFence {
#!/usr/bin/env bash
set -euo pipefail
bash build.sh --test internal/parser/parser

As per coding guidelines, use a package-scoped bash build.sh --test ... command for Go changes.

🤖 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.go` around lines 144 - 170, Update the
fence-closing logic in the markdown parsing loop around markdownFenceMarker so a
matching fence exits only when the marker’s trailing content is whitespace-only;
markers such as ```not-a-closer must keep the parser inside the fence. Add a
regression test in the parser package covering table-shaped content after such
an invalid closer, and validate with the package-scoped build.sh test command.

@wangq8
wangq8 marked this pull request as draft July 28, 2026 11:02
@wangq8
wangq8 marked this pull request as ready for review July 28, 2026 11:03
@wangq8 wangq8 added ci Continue Integration and removed ci Continue Integration labels Jul 28, 2026
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit c77741e into infiniflow:main Jul 29, 2026
9 checks passed
@dosubot

dosubot Bot commented Jul 29, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-08-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about ragflow Add Dosu to your team

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.

2 participants