Documentation
¶
Index ¶
Constants ¶
const HTMLTitleParserName = "html"
HTMLTitleParserName name of HTMLTitleParser for the parser factory
const MarkdownTitleParserName = "md"
MarkdownTitleParserName name of MarkdownTitleParser for the parser factory
const MultiParserName = "multi"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ContentEncoder ¶
ContentEncoder 对URL进行编码的函数,传入URL,传出编码后的结果
type Creator ¶
type Creator func(string) TitleParser
Creator 创建parser的函数类型,接受一个string作为顶层标题结构,被SetParser调用
type DefaultFilter ¶
type DefaultFilter struct { // 排除某些标题 ExcludeTitles []string // 排除符合regexp匹配的title ExcludeRegExp *regexp.Regexp }
func (*DefaultFilter) FilterTitleContent ¶
func (filter *DefaultFilter) FilterTitleContent(content string) bool
FilterTitleContent 根据title的内容过滤标题 返回true表示title需要被过滤
func (*DefaultFilter) SetExcludeRegExp ¶
func (filter *DefaultFilter) SetExcludeRegExp(reg string) (err error)
func (*DefaultFilter) SetExcludeTitles ¶
func (filter *DefaultFilter) SetExcludeTitles(titles string)
SetExcludeTitles 将由逗号分隔的一串标题分割成slice并设置
type Option ¶
type Option func(*Parser)
func WithURLEncoder ¶
func WithURLEncoder(encoder ContentEncoder) Option
WithURLEncoder 设置标题内容的编码器,非ascii字符作为URL时可能需要编码
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser 进行整个markdown的解析
type TitleFilter ¶
TitleFilter 根据规则过滤标题
type TitleNode ¶
type TitleNode struct {
// contains filtered or unexported fields
}
TitleNode 标题节点,按顶层标签构建的节点树 节点树的生长方向是单一的固定的, 假设节点按从左向右生长则最新添加的子节点一定在最右或者是最右子节点的后代
func NewTitleNode ¶
NewTitleNode 创建新节点,tag是html tag名称
func (*TitleNode) IsChildNode ¶
IsChildNode 检查node是否是当前节点的子节点 按tagName比较:h1 > h2 > ... > h5 因为markdown被顺序解析,所以tag更小意味着它是当前节点的子节点
type TitleParser ¶
type TitleParser interface { // content如果不是标题就返回nil,否则返回TitleNode Parse(content string) *TitleNode }
TitleParser 解析文件中的标题结构
func GetInnerParser ¶
func GetInnerParser(name, topTag string) (TitleParser, error)
GetInnerParser 获取标题解析器。topTag是可标题的最大级别(例如h1-h5中的h1)