@@ -23,6 +23,7 @@ import (
2323 "strconv"
2424 "strings"
2525
26+ "github.com/PuerkitoBio/goquery"
2627 "github.com/b3log/pipe/model"
2728 "github.com/b3log/pipe/service"
2829 "github.com/b3log/pipe/util"
@@ -219,7 +220,8 @@ func showArticleAction(c *gin.Context) {
219220 dataModel ["RelevantArticles" ] = articles
220221 fillPreviousArticle (c , article , & dataModel )
221222 fillNextArticle (c , article , & dataModel )
222- dataModel ["ToC" ] = "todo"
223+ logger .Info (mdResult .ContentHTML )
224+ dataModel ["ToC" ] = ToC (mdResult .ContentHTML )
223225 c .HTML (http .StatusOK , getTheme (c )+ "/article.html" , dataModel )
224226
225227 service .Article .IncArticleViewCount (article )
@@ -262,3 +264,23 @@ func fillNextArticle(c *gin.Context, article *model.Article, dataModel *DataMode
262264 }
263265 (* dataModel )["NextArticle" ] = nextArticle
264266}
267+
268+ func ToC (content string ) string {
269+ doc , _ := goquery .NewDocumentFromReader (strings .NewReader (content ))
270+ elements := doc .Find ("h1, h2, h3, h4, h5" )
271+ if nil == elements || 3 > elements .Length () {
272+ return ""
273+ }
274+
275+ ret := "<ul class=\" article-toc\" >"
276+ elements .Each (func (i int , ele * goquery.Selection ) {
277+ // ele.Nodes[0]
278+
279+ logger .Infof ("%+v" , ele )
280+
281+ })
282+
283+ _ = ret
284+
285+ return ""
286+ }
0 commit comments