Skip to content

Go: add Markdown parser - #16016

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix460
Jun 15, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix460

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(api/default)> parse file 'README.md';
Parsing Markdown file: README.md
--- AST tree:
HTMLBlock '<div align="center">\n<a href="https:…'

Type of change

  • New Feature (non-breaking change which adds functionality)

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds end-to-end markdown file ingestion support: a new FileTypeMarkdown constant maps the "md" extension in GetFileType, a new MarkdownParser struct backed by github.com/gomarkdown/markdown implements parsing, and GetParser is wired to dispatch markdown files to it. The go.mod adds the gomarkdown dependency and removes pdf_oxide/go and ebitengine/purego.

Changes

Markdown Ingestion Pipeline

Layer / File(s) Summary
FileTypeMarkdown constant, MarkdownParser, and GetParser wiring
internal/utility/file.go, internal/ingestion/parser/markdown_parser.go, internal/ingestion/parser/type.go
FileTypeMarkdown constant added with "md" extension recognized in GetFileType; MarkdownParser struct implemented with NewMarkdownParser constructor, Parse dispatch, GoMarkdownParse (prints AST to stdout), and String(); GetParser switch extended to return a MarkdownParser for FileTypeMarkdown.
go.mod dependency updates
go.mod
Adds github.com/gomarkdown/markdown as a direct dependency; removes github.com/yfedoseev/pdf_oxide/go and the indirect github.com/ebitengine/purego.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#15976: Modifies the same GetFileType/FileType constants in internal/utility/file.go and the GetParser factory in internal/ingestion/parser/type.go for a different parser (DOCX/office_oxide).

Poem

🐇 A markdown file hops down the lane,
Its headers and bullets parsed without pain.
GoMarkdown jumps in with extensions galore,
The AST prints out—then returns nil once more.
Another file type? The rabbit says: done! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go: add Markdown parser' clearly and concisely summarizes the main change: adding Markdown parsing functionality to the Go implementation.
Description check ✅ Passed The PR description includes both required template sections: 'What problem does this PR solve?' with a concrete example and 'Type of change' with 'New Feature' selected.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 15, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 15, 2026 06:20
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 15, 2026

@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/ingestion/parser/markdown_parser.go`:
- Line 47: Remove or gate behind explicit debug logging (off by default) the
stdout print statements in the markdown parser that expose user-provided content
and file metadata. Specifically, the fmt.Printf call that prints "Parsing
Markdown file" and similar stdout prints in the parser should be eliminated from
production code paths to prevent data leakage of user markdown content and file
metadata in runtime logs. If debug output is necessary for development purposes,
implement it using a debug logger that is disabled by default rather than direct
stdout printing.

In `@internal/utility/file.go`:
- Line 35: Update the FilenameType function (lines 103-112) to return
FileTypeMarkdown instead of FileTypeDOC when handling .md files, ensuring
consistent behavior with GetFileType which now correctly returns
FileTypeMarkdown for markdown files. Also review and align the related code at
lines 86-87 to ensure the classification is consistent across all utility
helpers.
🪄 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

Run ID: 3b43912e-2f74-4982-a4bf-5537460a71d2

📥 Commits

Reviewing files that changed from the base of the PR and between bc963f8 and e34fe7e.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • go.mod
  • internal/ingestion/parser/markdown_parser.go
  • internal/ingestion/parser/type.go
  • internal/utility/file.go

}

func (p *MarkdownParser) Parse(filename string, data []byte) error {
fmt.Printf("Parsing Markdown file: %s\n", filename)

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Do not print parsed document content/AST to stdout in parser path.

These stdout prints expose user-provided markdown content (via AST dump) and file metadata in runtime logs. This is a data leakage risk for ingestion workloads. Gate this behind explicit debug logging (off by default) or remove it from production code paths.

Also applies to: 63-65

🤖 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/ingestion/parser/markdown_parser.go` at line 47, Remove or gate
behind explicit debug logging (off by default) the stdout print statements in
the markdown parser that expose user-provided content and file metadata.
Specifically, the fmt.Printf call that prints "Parsing Markdown file" and
similar stdout prints in the parser should be eliminated from production code
paths to prevent data leakage of user markdown content and file metadata in
runtime logs. If debug output is necessary for development purposes, implement
it using a debug logger that is disabled by default rather than direct stdout
printing.

Comment thread internal/utility/file.go
FileTypePPTX FileType = "pptx"
FileTypeXLS FileType = "xls"
FileTypeXLSX FileType = "xlsx"
FileTypeMarkdown FileType = "md"

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align .md classification across utility helpers.

GetFileType now returns FileTypeMarkdown, but FilenameType still routes .md through FileTypeDOC (Line 103-112). This creates inconsistent parser routing depending on which helper a caller uses. Please update FilenameType so .md returns FileTypeMarkdown as well.

Also applies to: 86-87

🤖 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/utility/file.go` at line 35, Update the FilenameType function (lines
103-112) to return FileTypeMarkdown instead of FileTypeDOC when handling .md
files, ensuring consistent behavior with GetFileType which now correctly returns
FileTypeMarkdown for markdown files. Also review and align the related code at
lines 86-87 to ensure the classification is consistent across all utility
helpers.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (400dfd5) to head (e34fe7e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16016   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 2846216 into infiniflow:main Jun 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant