Skip to content

Commit

Permalink
📝 Add a template function runeLen #13438
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 12, 2024
1 parent 2f39c2f commit 29b5124
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id": "20201204184532-3qm9l8n",
"title": "Template snippet",
"type": "doc",
"updated": "20241212102051"
"updated": "20241212163918"
},
"Children": [
{
Expand Down Expand Up @@ -57,7 +57,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091444-jy56z0p",
"updated": "20241212102051"
"updated": "20241212163918"
},
"Children": [
{
Expand Down Expand Up @@ -215,7 +215,7 @@
"ListData": {},
"Properties": {
"id": "20210104091444-mwbvc9m",
"updated": "20241212102051"
"updated": "20241212163918"
},
"Children": [
{
Expand Down Expand Up @@ -495,15 +495,15 @@
},
"Properties": {
"id": "20241212102027-j293sei",
"updated": "20241212102051"
"updated": "20241212163902"
},
"Children": [
{
"ID": "20241212102028-6c8tlnu",
"Type": "NodeParagraph",
"Properties": {
"id": "20241212102028-6c8tlnu",
"updated": "20241212102051"
"updated": "20241212163902"
},
"Children": [
{
Expand All @@ -517,7 +517,7 @@
},
{
"Type": "NodeText",
"Data": "​: Statistics block content"
"Data": "​: This function is used to count the block content"
}
]
},
Expand Down Expand Up @@ -750,6 +750,43 @@
}
]
},
{
"ID": "20241212163841-3yjhffn",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20241212163841-3yjhffn",
"updated": "20241212163918"
},
"Children": [
{
"ID": "20241212163841-d8t3qxb",
"Type": "NodeParagraph",
"Properties": {
"id": "20241212163841-d8t3qxb",
"updated": "20241212163918"
},
"Children": [
{
"Type": "NodeText",
"Data": "​"
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "runeLen"
},
{
"Type": "NodeText",
"Data": "​: This function is used to return the string length"
}
]
}
]
},
{
"ID": "20211213121042-5n981ru",
"Type": "NodeListItem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id": "20201204181006-7bkppue",
"title": "模板片段",
"type": "doc",
"updated": "20241212101821"
"updated": "20241212163739"
},
"Children": [
{
Expand Down Expand Up @@ -69,7 +69,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091309-fhb549c",
"updated": "20241212101821"
"updated": "20241212163739"
},
"Children": [
{
Expand Down Expand Up @@ -237,7 +237,7 @@
"ListData": {},
"Properties": {
"id": "20210104091309-gjkg3u5",
"updated": "20241212101821"
"updated": "20241212163739"
},
"Children": [
{
Expand Down Expand Up @@ -517,15 +517,15 @@
},
"Properties": {
"id": "20241212101708-0euo6is",
"updated": "20241212101821"
"updated": "20241212163723"
},
"Children": [
{
"ID": "20241212101708-llv0ngj",
"Type": "NodeParagraph",
"Properties": {
"id": "20241212101708-llv0ngj",
"updated": "20241212101734"
"updated": "20241212163723"
},
"Children": [
{
Expand All @@ -539,7 +539,7 @@
},
{
"Type": "NodeText",
"Data": "​:统计块内容"
"Data": "​:该函数用于统计块内容"
}
]
},
Expand Down Expand Up @@ -772,6 +772,43 @@
}
]
},
{
"ID": "20241212163704-qmyz1ss",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20241212163704-qmyz1ss",
"updated": "20241212163739"
},
"Children": [
{
"ID": "20241212163704-i9p11h6",
"Type": "NodeParagraph",
"Properties": {
"id": "20241212163704-i9p11h6",
"updated": "20241212163739"
},
"Children": [
{
"Type": "NodeText",
"Data": "​"
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "runeLen"
},
{
"Type": "NodeText",
"Data": "​:该函数用于返回字符串长度"
}
]
}
]
},
{
"ID": "20211213120813-ppm3j85",
"Type": "NodeListItem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"id": "20211226123004-dplpw0o",
"title": "範本片段",
"type": "doc",
"updated": "20241212102113"
"updated": "20241212164017"
},
"Children": [
{
Expand Down Expand Up @@ -53,7 +53,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226123024-eyagqur",
"updated": "20241212102113"
"updated": "20241212164017"
},
"Children": [
{
Expand Down Expand Up @@ -208,7 +208,7 @@
"ListData": {},
"Properties": {
"id": "20211226123024-pjvw31z",
"updated": "20241212102113"
"updated": "20241212164017"
},
"Children": [
{
Expand Down Expand Up @@ -496,7 +496,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20241212102021-54wv84h",
"updated": "20241212102113"
"updated": "20241212164010"
},
"Children": [
{
Expand All @@ -510,7 +510,7 @@
},
{
"Type": "NodeText",
"Data": "​:統計區塊內容"
"Data": "​:此函數用於統計區塊內容"
}
]
},
Expand Down Expand Up @@ -743,6 +743,43 @@
}
]
},
{
"ID": "20241212164016-nxteno5",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20241212164016-nxteno5",
"updated": "20241212164017"
},
"Children": [
{
"ID": "20241212164016-ot8vo9l",
"Type": "NodeParagraph",
"Properties": {
"id": "20241212164016-ot8vo9l",
"updated": "20241212164017"
},
"Children": [
{
"Type": "NodeText",
"Data": "​"
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "runeLen"
},
{
"Type": "NodeText",
"Data": "​:此函數用於傳回字串長度"
}
]
}
]
},
{
"ID": "20211226123024-kca62r8",
"Type": "NodeListItem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": "20240530101000-6x9ivi7",
"title": "テンプレートスニペット",
"type": "doc",
"updated": "20241212102145"
"updated": "20241212163955"
},
"Children": [
{
Expand Down Expand Up @@ -66,7 +66,7 @@
"Properties": {
"ID": "20240530101000-5nvn9ad",
"id": "20240530101000-pi05yzt",
"updated": "20241212102145"
"updated": "20241212163955"
},
"Children": [
{
Expand Down Expand Up @@ -226,7 +226,7 @@
"ListData": {},
"Properties": {
"id": "20240530101000-by5hqnb",
"updated": "20241212102145"
"updated": "20241212163955"
},
"Children": [
{
Expand Down Expand Up @@ -514,7 +514,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20241212102033-d4azb7k",
"updated": "20241212102145"
"updated": "20241212163936"
},
"Children": [
{
Expand All @@ -528,7 +528,7 @@
},
{
"Type": "NodeText",
"Data": "​:統計ブロックの内容"
"Data": "​:この関数はブロックの内容を数えるために使用されます"
}
]
},
Expand Down Expand Up @@ -761,6 +761,43 @@
}
]
},
{
"ID": "20241212163938-ewajrsj",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20241212163938-ewajrsj",
"updated": "20241212163955"
},
"Children": [
{
"ID": "20241212163938-y1al3b9",
"Type": "NodeParagraph",
"Properties": {
"id": "20241212163938-y1al3b9",
"updated": "20241212163955"
},
"Children": [
{
"Type": "NodeText",
"Data": "​"
},
{
"Type": "NodeTextMark",
"TextMarkType": "code",
"TextMarkTextContent": "runeLen"
},
{
"Type": "NodeText",
"Data": "​: この関数は文字列の長さを返すために使用されます"
}
]
}
]
},
{
"ID": "20240530101000-xhrxvp5",
"Type": "NodeListItem",
Expand Down
6 changes: 6 additions & 0 deletions kernel/filesys/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math"
"text/template"
"time"
"unicode/utf8"

"github.com/88250/go-humanize"
"github.com/Masterminds/sprig/v3"
Expand Down Expand Up @@ -50,9 +51,14 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
ret["FormatFloat"] = FormatFloat
ret["getHPathByID"] = getHPathByID
ret["statBlock"] = StatBlock
ret["runeLen"] = runeLen
return
}

func runeLen(s string) int {
return utf8.RuneCountInString(s)
}

func pow(a, b interface{}) int64 { return int64(math.Pow(cast.ToFloat64(a), cast.ToFloat64(b))) }
func powf(a, b interface{}) float64 { return math.Pow(cast.ToFloat64(a), cast.ToFloat64(b)) }
func log(a, b interface{}) int64 {
Expand Down

0 comments on commit 29b5124

Please sign in to comment.