mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Add word count template function runeCount and wordCount https://github.com/siyuan-note/siyuan/issues/13625
This commit is contained in:
parent
353cf08fd9
commit
2f1885b07e
5 changed files with 326 additions and 43 deletions
|
|
@ -20,9 +20,9 @@ import (
|
|||
"math"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/88250/go-humanize"
|
||||
util2 "github.com/88250/lute/util"
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
|
@ -51,12 +51,19 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
|
|||
ret["FormatFloat"] = FormatFloat
|
||||
ret["getHPathByID"] = getHPathByID
|
||||
ret["statBlock"] = StatBlock
|
||||
ret["runeLen"] = runeLen
|
||||
ret["runeCount"] = runeCount
|
||||
ret["wordCount"] = wordCount
|
||||
return
|
||||
}
|
||||
|
||||
func runeLen(s string) int {
|
||||
return utf8.RuneCountInString(s)
|
||||
func runeCount(s string) (ret int) {
|
||||
ret, _ = util2.WordCount(s)
|
||||
return
|
||||
}
|
||||
|
||||
func wordCount(s string) (ret int) {
|
||||
_, ret = util2.WordCount(s)
|
||||
return
|
||||
}
|
||||
|
||||
func pow(a, b interface{}) int64 { return int64(math.Pow(cast.ToFloat64(a), cast.ToFloat64(b))) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue