Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProcessHTMLWithDiag ¶
func ProcessHTMLWithDiag(ctx context.Context, htmlContent string, baseURL string) (*HTMLResult, *DiagnosticInfo, error)
ProcessHTMLWithDiag 带诊断的 HTML 处理(用于测试)
Types ¶
type DiagnosticInfo ¶
type DiagnosticInfo struct {
ReadabilityOK bool
ReadabilityTitle string
ContentLength int
StructureTags map[string]int // 标签名 → 数量
// 各阶段快照
StagePreCleanLen int // 预清理后 HTML 长度
StageAnchoredLen int // 结构锚定后 HTML 长度
StageExtractSrc string // 提取来源: "readability" | "heuristic"
StageExtractLen int // 提取后内容 HTML 长度
StageConvertLen int // markdown 转换后长度
StageFinalLen int // 最终 markdown 长度
PreBlocksInput int // 保护前 <pre> 数
PreBlocksRestored int // 回填成功数
PreBlocksLost int // 回填失败数
TableHeadersPromoted int // 提升表头数
TitleInjected bool
}
DiagnosticInfo 诊断信息(用于测试和调试)
type HTMLResult ¶
type HTMLResult struct {
Title string
Markdown string
Byline string
PublishedTime *time.Time
PreBlocksInput int
PreBlocksRestored int
PreBlocksLost int
TableHeadersPromoted int
TitleInjected bool
}
HTMLResult HTML 处理结果
func ProcessHTML ¶
ProcessHTML 完整的 HTML → Markdown 管线 管线:代码块保护 → 预清理 → 结构保护 → readability 提取 → 回填/后处理 → html→md
type Options ¶
type Options struct {
MaxInlineLines int
MaxInlineChars int
MaxContentLength int // 内容超过此长度也写文件,默认 100000
FileOutputDir string
Store StoreWriter
// PDF 内容(application/pdf)解析选项;nil 时用默认(MaxPages 200 + Heuristic)。
PDF *PDFOptions
}
Options 内容处理选项
type Output ¶
type Output struct {
Mode string // "inline" | "saved_to_file"
Title string
Markdown string // Mode=inline 时有值
FilePath string // Mode=saved_to_file 时有值
TotalLines int
TotalChars int
Summary string
AgentHint string
StatusCode int
ContType string
PageCount int // PDF 内容:文档总页数;非 PDF 为 0
Pages []int // PDF 内容:实际提取的页码
Byline string
PublishedTime *time.Time
PreBlocksInput int
PreBlocksRestored int
PreBlocksLost int
TableHeadersPromoted int
TitleInjected bool
}
Output 内容处理输出
type PDFOptions ¶
type PDFOptions struct {
MaxPages int
Heuristic bool
// Pages 指定解析的页码(1-based,自动去重升序、过滤越界页)。
// 非空时优先于 MaxPages;全部越界时报错。
Pages []int
}
PDFOptions PDF 解析选项
type PDFParseError ¶
PDFParseError PDF 解析错误
func (*PDFParseError) Error ¶
func (e *PDFParseError) Error() string
type PDFParseResult ¶
type PDFParseResult struct {
SourcePath string
Title string
PageCount int // 文档总页数(不受 Pages/MaxPages 影响)
Pages []int // 实际提取的页码
Method string
Markdown string
}
PDFParseResult PDF 解析结果(内部)
func ParsePDFBytes ¶
func ParsePDFBytes(ctx context.Context, data []byte, name string, opts PDFOptions) (*PDFParseResult, error)
ParsePDFBytes 解析 PDF 字节流
func ParsePDFFile ¶
func ParsePDFFile(ctx context.Context, filePath string, opts PDFOptions) (*PDFParseResult, error)
ParsePDFFile 解析本地 PDF 文件
type StoreWriter ¶
type StoreWriter interface {
WriteMarkdown(content string, title string, sourceURL string) (filePath string, totalLines int, totalChars int, summary string, err error)
WriteMarkdownFromReader(r io.Reader, title string, sourceURL string) (filePath string, totalLines int, totalChars int, summary string, err error)
}
StoreWriter 文件写入接口(支持 mock)