🎨 Add word count template function runeCount and wordCount https://github.com/siyuan-note/siyuan/issues/13625

This commit is contained in:
Daniel 2024-12-25 19:31:56 +08:00
parent 353cf08fd9
commit 2f1885b07e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 326 additions and 43 deletions

View file

@ -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))) }