forked from forgejo/forgejo
Improve Wiki TOC (#24137)
The old code has a lot of technical debts, eg: `repo/wiki/view.tmpl` / `Iterate` This PR improves the Wiki TOC display and improves the code. --------- Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
parent
f045e58cc7
commit
1ab16e48cc
12 changed files with 129 additions and 118 deletions
|
@ -13,10 +13,14 @@ import (
|
|||
"github.com/yuin/goldmark/ast"
|
||||
)
|
||||
|
||||
func createTOCNode(toc []markup.Header, lang string) ast.Node {
|
||||
func createTOCNode(toc []markup.Header, lang string, detailsAttrs map[string]string) ast.Node {
|
||||
details := NewDetails()
|
||||
summary := NewSummary()
|
||||
|
||||
for k, v := range detailsAttrs {
|
||||
details.SetAttributeString(k, []byte(v))
|
||||
}
|
||||
|
||||
summary.AppendChild(summary, ast.NewString([]byte(translation.NewLocale(lang).Tr("toc"))))
|
||||
details.AppendChild(details, summary)
|
||||
ul := ast.NewList('-')
|
||||
|
@ -40,7 +44,7 @@ func createTOCNode(toc []markup.Header, lang string) ast.Node {
|
|||
}
|
||||
li := ast.NewListItem(currentLevel * 2)
|
||||
a := ast.NewLink()
|
||||
a.Destination = []byte(fmt.Sprintf("#%s", url.PathEscape(header.ID)))
|
||||
a.Destination = []byte(fmt.Sprintf("#%s", url.QueryEscape(header.ID)))
|
||||
a.AppendChild(a, ast.NewString([]byte(header.Text)))
|
||||
li.AppendChild(li, a)
|
||||
ul.AppendChild(ul, li)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue