📝 Add a template function runeLen
https://github.com/siyuan-note/siyuan/issues/13438
This commit is contained in:
parent
2f39c2f1bc
commit
29b5124591
5 changed files with 176 additions and 22 deletions
|
@ -6,7 +6,7 @@
|
|||
"id": "20201204184532-3qm9l8n",
|
||||
"title": "Template snippet",
|
||||
"type": "doc",
|
||||
"updated": "20241212102051"
|
||||
"updated": "20241212163918"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -57,7 +57,7 @@
|
|||
"HeadingLevel": 2,
|
||||
"Properties": {
|
||||
"id": "20210104091444-jy56z0p",
|
||||
"updated": "20241212102051"
|
||||
"updated": "20241212163918"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -215,7 +215,7 @@
|
|||
"ListData": {},
|
||||
"Properties": {
|
||||
"id": "20210104091444-mwbvc9m",
|
||||
"updated": "20241212102051"
|
||||
"updated": "20241212163918"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -495,7 +495,7 @@
|
|||
},
|
||||
"Properties": {
|
||||
"id": "20241212102027-j293sei",
|
||||
"updated": "20241212102051"
|
||||
"updated": "20241212163902"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -503,7 +503,7 @@
|
|||
"Type": "NodeParagraph",
|
||||
"Properties": {
|
||||
"id": "20241212102028-6c8tlnu",
|
||||
"updated": "20241212102051"
|
||||
"updated": "20241212163902"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -517,7 +517,7 @@
|
|||
},
|
||||
{
|
||||
"Type": "NodeText",
|
||||
"Data": ": Statistics block content"
|
||||
"Data": ": This function is used to count the block content"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"id": "20201204181006-7bkppue",
|
||||
"title": "模板片段",
|
||||
"type": "doc",
|
||||
"updated": "20241212101821"
|
||||
"updated": "20241212163739"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -69,7 +69,7 @@
|
|||
"HeadingLevel": 2,
|
||||
"Properties": {
|
||||
"id": "20210104091309-fhb549c",
|
||||
"updated": "20241212101821"
|
||||
"updated": "20241212163739"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -237,7 +237,7 @@
|
|||
"ListData": {},
|
||||
"Properties": {
|
||||
"id": "20210104091309-gjkg3u5",
|
||||
"updated": "20241212101821"
|
||||
"updated": "20241212163739"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -517,7 +517,7 @@
|
|||
},
|
||||
"Properties": {
|
||||
"id": "20241212101708-0euo6is",
|
||||
"updated": "20241212101821"
|
||||
"updated": "20241212163723"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -525,7 +525,7 @@
|
|||
"Type": "NodeParagraph",
|
||||
"Properties": {
|
||||
"id": "20241212101708-llv0ngj",
|
||||
"updated": "20241212101734"
|
||||
"updated": "20241212163723"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -539,7 +539,7 @@
|
|||
},
|
||||
{
|
||||
"Type": "NodeText",
|
||||
"Data": ":统计块内容"
|
||||
"Data": ":该函数用于统计块内容"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"id": "20211226123004-dplpw0o",
|
||||
"title": "範本片段",
|
||||
"type": "doc",
|
||||
"updated": "20241212102113"
|
||||
"updated": "20241212164017"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -53,7 +53,7 @@
|
|||
"HeadingLevel": 2,
|
||||
"Properties": {
|
||||
"id": "20211226123024-eyagqur",
|
||||
"updated": "20241212102113"
|
||||
"updated": "20241212164017"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -208,7 +208,7 @@
|
|||
"ListData": {},
|
||||
"Properties": {
|
||||
"id": "20211226123024-pjvw31z",
|
||||
"updated": "20241212102113"
|
||||
"updated": "20241212164017"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -496,7 +496,7 @@
|
|||
"Type": "NodeParagraph",
|
||||
"Properties": {
|
||||
"id": "20241212102021-54wv84h",
|
||||
"updated": "20241212102113"
|
||||
"updated": "20241212164010"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -510,7 +510,7 @@
|
|||
},
|
||||
{
|
||||
"Type": "NodeText",
|
||||
"Data": ":統計區塊內容"
|
||||
"Data": ":此函數用於統計區塊內容"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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",
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"id": "20240530101000-6x9ivi7",
|
||||
"title": "テンプレートスニペット",
|
||||
"type": "doc",
|
||||
"updated": "20241212102145"
|
||||
"updated": "20241212163955"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -66,7 +66,7 @@
|
|||
"Properties": {
|
||||
"ID": "20240530101000-5nvn9ad",
|
||||
"id": "20240530101000-pi05yzt",
|
||||
"updated": "20241212102145"
|
||||
"updated": "20241212163955"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -226,7 +226,7 @@
|
|||
"ListData": {},
|
||||
"Properties": {
|
||||
"id": "20240530101000-by5hqnb",
|
||||
"updated": "20241212102145"
|
||||
"updated": "20241212163955"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -514,7 +514,7 @@
|
|||
"Type": "NodeParagraph",
|
||||
"Properties": {
|
||||
"id": "20241212102033-d4azb7k",
|
||||
"updated": "20241212102145"
|
||||
"updated": "20241212163936"
|
||||
},
|
||||
"Children": [
|
||||
{
|
||||
|
@ -528,7 +528,7 @@
|
|||
},
|
||||
{
|
||||
"Type": "NodeText",
|
||||
"Data": ":統計ブロックの内容"
|
||||
"Data": ":この関数はブロックの内容を数えるために使用されます"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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",
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"math"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/88250/go-humanize"
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue