MCPcopy Index your code
hub / github.com/TruthHun/BookStack / ParseTitleFromMdHtml

Function ParseTitleFromMdHtml

utils/file.go:103–115  ·  view source on GitHub ↗

从md的html文件中提取文章标题(从h1-h6)

(html string)

Source from the content-addressed store, hash-verified

101
102//从md的html文件中提取文章标题(从h1-h6)
103func ParseTitleFromMdHtml(html string) (title string) {
104 hTag := []string{"h1", "h2", "h3", "h4", "h5", "h6"}
105 if doc, err := goquery.NewDocumentFromReader(strings.NewReader(html)); err == nil {
106 for _, tag := range hTag {
107 if title = strings.TrimSpace(doc.Find(tag).First().Text()); title != "" {
108 return title
109 }
110 }
111 } else {
112 beego.Error(err.Error())
113 }
114 return "空标题文档"
115}
116
117// ExecuteViewPathTemplate 执行指定的模板并返回执行结果.
118//@param tplName 模板文件路径

Callers 4

unzipToDataMethod · 0.92
loadByFolderMethod · 0.92
AutoTitleMethod · 0.92
SplitMarkdownAndStoreMethod · 0.92

Calls 1

FindMethod · 0.45

Tested by

no test coverage detected