21 lines
404 B
Go
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
|
|
}
|