从md的html文件中提取文章标题(从h1-h6)
(html string)
| 101 | |
| 102 | //从md的html文件中提取文章标题(从h1-h6) |
| 103 | func 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 模板文件路径 |
no test coverage detected