Files
rag-local/common/text_parser.go
T
2026-08-05 10:28:44 +08:00

21 lines
404 B
Go

package common
import (
"os"
"strings"
)
type textParser struct{}
// Parse txt / md:直接读全文。md 保留 # 标题行供分块器识别
func (p *textParser) Parse(path string) (string, error) {
b, err := os.ReadFile(path)
if err != nil {
return "", err
}
text := string(b)
text = strings.ReplaceAll(text, "\r\n", "\n")
text = strings.ReplaceAll(text, "\r", "\n")
return text, nil
}