forked from forgejo/forgejo
Automatically render wiki TOC (#19873)
Automatically add sidebar in the wiki view containing a TOC for the wiki page. Make the TOC collapsable Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
c1c07e533c
commit
ac88f21ecc
8 changed files with 146 additions and 50 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
texttmpl "text/template"
|
||||
"time"
|
||||
|
@ -390,6 +391,66 @@ func NewFuncMap() []template.FuncMap {
|
|||
"Join": strings.Join,
|
||||
"QueryEscape": url.QueryEscape,
|
||||
"DotEscape": DotEscape,
|
||||
"Iterate": func(arg interface{}) (items []uint64) {
|
||||
count := uint64(0)
|
||||
switch val := arg.(type) {
|
||||
case uint64:
|
||||
count = val
|
||||
case *uint64:
|
||||
count = *val
|
||||
case int64:
|
||||
if val < 0 {
|
||||
val = 0
|
||||
}
|
||||
count = uint64(val)
|
||||
case *int64:
|
||||
if *val < 0 {
|
||||
*val = 0
|
||||
}
|
||||
count = uint64(*val)
|
||||
case int:
|
||||
if val < 0 {
|
||||
val = 0
|
||||
}
|
||||
count = uint64(val)
|
||||
case *int:
|
||||
if *val < 0 {
|
||||
*val = 0
|
||||
}
|
||||
count = uint64(*val)
|
||||
case uint:
|
||||
count = uint64(val)
|
||||
case *uint:
|
||||
count = uint64(*val)
|
||||
case int32:
|
||||
if val < 0 {
|
||||
val = 0
|
||||
}
|
||||
count = uint64(val)
|
||||
case *int32:
|
||||
if *val < 0 {
|
||||
*val = 0
|
||||
}
|
||||
count = uint64(*val)
|
||||
case uint32:
|
||||
count = uint64(val)
|
||||
case *uint32:
|
||||
count = uint64(*val)
|
||||
case string:
|
||||
cnt, _ := strconv.ParseInt(val, 10, 64)
|
||||
if cnt < 0 {
|
||||
cnt = 0
|
||||
}
|
||||
count = uint64(cnt)
|
||||
}
|
||||
if count <= 0 {
|
||||
return items
|
||||
}
|
||||
for i := uint64(0); i < count; i++ {
|
||||
items = append(items, i)
|
||||
}
|
||||
return items
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue