Repository navigation
Porting change from #17477 python to go, parse table into chunk for markdown file - #17488
Conversation
…hunk for markdown file
📝 WalkthroughWalkthroughThe Markdown parser now detects inline tables outside fenced code blocks, renders them as HTML, and returns the transformed text through ChangesMarkdown table rendering
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
internal/parser/parser/markdown_parser.gointernal/parser/parser/markdown_parser_test.go
| 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"}}, | ||
| } |
There was a problem hiding this comment.
🗄️ 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.
| 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 |
There was a problem hiding this comment.
🎯 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/parserAs 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.
|
LGTM |
📄 Knowledge reviewDosu skipped reviewing this PR because your organization has used its |
…hunk for markdown file (infiniflow#17488) Porting change from infiniflow#17477 python to go, parse table into chunk for markdown file Before: <img width="3606" height="1805" alt="image" src="https://github.com/user-attachments/assets/363698be-c182-40cf-a167-0f0c13a68b12" /> After: <img width="3606" height="1805" alt="image" src="https://github.com/user-attachments/assets/9d0d18cb-843e-4a1a-b176-16ac32998310" />
Porting change from #17477 python to go, parse table into chunk for markdown file

Before:
After:
