diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201204184532-3qm9l8n.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201204184532-3qm9l8n.sy index 35b157bab..171e57376 100644 --- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201204184532-3qm9l8n.sy +++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201204184532-3qm9l8n.sy @@ -6,7 +6,7 @@ "id": "20201204184532-3qm9l8n", "title": "Template snippet", "type": "doc", - "updated": "20241224162810" + "updated": "20241225192808" }, "Children": [ { @@ -57,7 +57,7 @@ "HeadingLevel": 2, "Properties": { "id": "20210104091444-jy56z0p", - "updated": "20241224162810" + "updated": "20241225192808" }, "Children": [ { @@ -215,7 +215,7 @@ "ListData": {}, "Properties": { "id": "20210104091444-mwbvc9m", - "updated": "20241224162810" + "updated": "20241225192808" }, "Children": [ { @@ -249,7 +249,15 @@ }, { "Type": "NodeText", - "Data": "​: Use this variable to insert the current document name. For example, if the template content is " + "Data": "​: Use this variable to insert the current document name. For example, if the " + }, + { + "Type": "NodeText", + "Data": "template" + }, + { + "Type": "NodeText", + "Data": " content is " }, { "Type": "NodeTextMark", @@ -443,7 +451,15 @@ }, { "Type": "NodeText", - "Data": "​: This function is used to query the database, and the return value is a list of blocks" + "Data": "​: This function is used to query the " + }, + { + "Type": "NodeText", + "Data": "database" + }, + { + "Type": "NodeText", + "Data": ", and the return value is a list of blocks" } ] }, @@ -453,6 +469,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215602-dk7iion", + "style": "line-height: 22px;", "updated": "20241213215602" }, "Children": [ @@ -506,7 +523,15 @@ }, { "Type": "NodeText", - "Data": "​: This function is used to query the database, and the return value is a list of spans" + "Data": "​: This function is used to query the " + }, + { + "Type": "NodeText", + "Data": "database" + }, + { + "Type": "NodeText", + "Data": ", and the return value is a list of spans" } ] }, @@ -516,6 +541,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215606-a1mq6zf", + "style": "line-height: 22px;", "updated": "20241224162810" }, "Children": [ @@ -569,7 +595,15 @@ }, { "Type": "NodeText", - "Data": "​: This function is used to query the database and the return value is a result set" + "Data": "​: This function is used to query the " + }, + { + "Type": "NodeText", + "Data": "database" + }, + { + "Type": "NodeText", + "Data": " and the return value is a result set" } ] }, @@ -579,6 +613,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215554-rox3jk7", + "style": "line-height: 22px;", "updated": "20241213215554" }, "Children": [ @@ -642,6 +677,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215714-u0j3i4k", + "style": "line-height: 22px;", "updated": "20241213215714" }, "Children": [ @@ -860,7 +896,7 @@ "Type": "NodeParagraph", "Properties": { "id": "20241212163841-d8t3qxb", - "updated": "20241212163918" + "updated": "20241225192802" }, "Children": [ { @@ -870,11 +906,48 @@ { "Type": "NodeTextMark", "TextMarkType": "code", - "TextMarkTextContent": "runeLen" + "TextMarkTextContent": "runeCount" }, { "Type": "NodeText", - "Data": "​: This function is used to return the string length" + "Data": "​: This function is used to return the number of characters in a string" + } + ] + } + ] + }, + { + "ID": "20241225192802-4sojmmk", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20241225192802-4sojmmk", + "updated": "20241225192808" + }, + "Children": [ + { + "ID": "20241225192802-0rma1gp", + "Type": "NodeParagraph", + "Properties": { + "id": "20241225192802-0rma1gp", + "updated": "20241225192808" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "​" + }, + { + "Type": "NodeTextMark", + "TextMarkType": "code", + "TextMarkTextContent": "wordCount" + }, + { + "Type": "NodeText", + "Data": "​: This function is used to return the number of words in a string" } ] } diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201204181006-7bkppue.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201204181006-7bkppue.sy index 7db81fdf7..15407df63 100644 --- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201204181006-7bkppue.sy +++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201204181006-7bkppue.sy @@ -6,7 +6,7 @@ "id": "20201204181006-7bkppue", "title": "模板片段", "type": "doc", - "updated": "20241224162826" + "updated": "20241225192538" }, "Children": [ { @@ -69,7 +69,7 @@ "HeadingLevel": 2, "Properties": { "id": "20210104091309-fhb549c", - "updated": "20241224162826" + "updated": "20241225192538" }, "Children": [ { @@ -237,7 +237,7 @@ "ListData": {}, "Properties": { "id": "20210104091309-gjkg3u5", - "updated": "20241224162826" + "updated": "20241225192538" }, "Children": [ { @@ -271,7 +271,15 @@ }, { "Type": "NodeText", - "Data": "​:该变量用于插入当前文档名。比如模板内容为 " + "Data": "​:该变量用于插入当前文档名。比如" + }, + { + "Type": "NodeText", + "Data": "模板" + }, + { + "Type": "NodeText", + "Data": "内容为 " }, { "Type": "NodeTextMark", @@ -465,7 +473,15 @@ }, { "Type": "NodeText", - "Data": "​:该函数用于查询数据库,返回值为 blocks 列表" + "Data": "​:该函数用于查询" + }, + { + "Type": "NodeText", + "Data": "数据库" + }, + { + "Type": "NodeText", + "Data": ",返回值为 blocks 列表" } ] }, @@ -475,6 +491,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20210604111446-p6vadfc", + "style": "line-height: 22px;", "updated": "20241213215118" }, "Children": [ @@ -528,7 +545,15 @@ }, { "Type": "NodeText", - "Data": "​:该函数用于查询数据库,返回值为 spans 列表" + "Data": "​:该函数用于查询" + }, + { + "Type": "NodeText", + "Data": "数据库" + }, + { + "Type": "NodeText", + "Data": ",返回值为 spans 列表" } ] }, @@ -538,6 +563,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215337-rhkoc8k", + "style": "line-height: 22px;", "updated": "20241224162826" }, "Children": [ @@ -591,7 +617,15 @@ }, { "Type": "NodeText", - "Data": "​:该函数用于查询数据库,返回值为结果集" + "Data": "​:该函数用于查询" + }, + { + "Type": "NodeText", + "Data": "数据库" + }, + { + "Type": "NodeText", + "Data": ",返回值为结果集" } ] }, @@ -601,6 +635,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215240-f33bsqs", + "style": "line-height: 22px;", "updated": "20241213215421" }, "Children": [ @@ -664,6 +699,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241212101810-6ffociu", + "style": "line-height: 22px;", "updated": "20241213215655" }, "Children": [ @@ -882,7 +918,7 @@ "Type": "NodeParagraph", "Properties": { "id": "20241212163704-i9p11h6", - "updated": "20241212163739" + "updated": "20241225192521" }, "Children": [ { @@ -892,11 +928,48 @@ { "Type": "NodeTextMark", "TextMarkType": "code", - "TextMarkTextContent": "runeLen" + "TextMarkTextContent": "runeCount" }, { "Type": "NodeText", - "Data": "​:该函数用于返回字符串长度" + "Data": "​:该函数用于返回字符串中的字符数" + } + ] + } + ] + }, + { + "ID": "20241225192524-3b660ss", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20241225192524-3b660ss", + "updated": "20241225192538" + }, + "Children": [ + { + "ID": "20241225192524-vyuve5f", + "Type": "NodeParagraph", + "Properties": { + "id": "20241225192524-vyuve5f", + "updated": "20241225192538" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "​" + }, + { + "Type": "NodeTextMark", + "TextMarkType": "code", + "TextMarkTextContent": "wordCount" + }, + { + "Type": "NodeText", + "Data": "​:该函数用于返回字符串中的字数" } ] } diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123004-dplpw0o.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123004-dplpw0o.sy index 67b67b503..7586b7b13 100644 --- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123004-dplpw0o.sy +++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123004-dplpw0o.sy @@ -6,7 +6,7 @@ "id": "20211226123004-dplpw0o", "title": "範本片段", "type": "doc", - "updated": "20241224162821" + "updated": "20241225192757" }, "Children": [ { @@ -53,7 +53,7 @@ "HeadingLevel": 2, "Properties": { "id": "20211226123024-eyagqur", - "updated": "20241224162821" + "updated": "20241225192757" }, "Children": [ { @@ -208,7 +208,7 @@ "ListData": {}, "Properties": { "id": "20211226123024-pjvw31z", - "updated": "20241224162821" + "updated": "20241225192757" }, "Children": [ { @@ -436,7 +436,15 @@ }, { "Type": "NodeText", - "Data": "​:該函數用於查詢資料庫,返回值為 blocks 列表" + "Data": "​:該函數用於查詢" + }, + { + "Type": "NodeText", + "Data": "資料庫" + }, + { + "Type": "NodeText", + "Data": ",返回值為 blocks 列表" } ] }, @@ -446,6 +454,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215519-mfgruqs", + "style": "line-height: 22px;", "updated": "20241213215519" }, "Children": [ @@ -499,7 +508,15 @@ }, { "Type": "NodeText", - "Data": "​:該函數用於查詢資料庫,返回值為 spans 列表" + "Data": "​:該函數用於查詢" + }, + { + "Type": "NodeText", + "Data": "資料庫" + }, + { + "Type": "NodeText", + "Data": ",返回值為 spans 列表" } ] }, @@ -509,6 +526,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215524-9an3khb", + "style": "line-height: 22px;", "updated": "20241224162821" }, "Children": [ @@ -562,7 +580,15 @@ }, { "Type": "NodeText", - "Data": "​:函數用於查詢資料庫,傳回值為結果集" + "Data": "​:函數用於查詢" + }, + { + "Type": "NodeText", + "Data": "資料庫" + }, + { + "Type": "NodeText", + "Data": ",傳回值為結果集" } ] }, @@ -572,6 +598,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215530-f2iwrjz", + "style": "line-height: 22px;", "updated": "20241213215530" }, "Children": [ @@ -635,6 +662,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215707-lxpmd6b", + "style": "line-height: 22px;", "updated": "20241213215707" }, "Children": [ @@ -845,7 +873,7 @@ }, "Properties": { "id": "20241212164016-nxteno5", - "updated": "20241212164017" + "updated": "20241225192757" }, "Children": [ { @@ -853,7 +881,7 @@ "Type": "NodeParagraph", "Properties": { "id": "20241212164016-ot8vo9l", - "updated": "20241212164017" + "updated": "20241225192757" }, "Children": [ { @@ -863,11 +891,48 @@ { "Type": "NodeTextMark", "TextMarkType": "code", - "TextMarkTextContent": "runeLen" + "TextMarkTextContent": "runeCount" }, { "Type": "NodeText", - "Data": "​:此函數用於傳回字串長度" + "Data": "​:該函數用於傳回字符串中的字符數" + } + ] + } + ] + }, + { + "ID": "20241225192712-lunq7os", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20241225192712-lunq7os", + "updated": "20241225192723" + }, + "Children": [ + { + "ID": "20241225192712-sk60mxv", + "Type": "NodeParagraph", + "Properties": { + "id": "20241225192712-sk60mxv", + "updated": "20241225192723" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "​" + }, + { + "Type": "NodeTextMark", + "TextMarkType": "code", + "TextMarkTextContent": "wordCount" + }, + { + "Type": "NodeText", + "Data": "​:該函數用於傳回字符串中的字數" } ] } diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-6x9ivi7.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-6x9ivi7.sy index b3609e1d4..4c76f248c 100644 --- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-6x9ivi7.sy +++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-6x9ivi7.sy @@ -7,7 +7,7 @@ "id": "20240530101000-6x9ivi7", "title": "テンプレートスニペット", "type": "doc", - "updated": "20241224162728" + "updated": "20241225192831" }, "Children": [ { @@ -66,7 +66,7 @@ "Properties": { "ID": "20240530101000-5nvn9ad", "id": "20240530101000-pi05yzt", - "updated": "20241224162728" + "updated": "20241225192831" }, "Children": [ { @@ -226,7 +226,7 @@ "ListData": {}, "Properties": { "id": "20240530101000-by5hqnb", - "updated": "20241224162728" + "updated": "20241225192831" }, "Children": [ { @@ -454,7 +454,15 @@ }, { "Type": "NodeText", - "Data": "​: この関数はデータベースをクエリしてブロックのリストを返します" + "Data": "​: この関数は" + }, + { + "Type": "NodeText", + "Data": "データベース" + }, + { + "Type": "NodeText", + "Data": "をクエリしてブロックのリストを返します" } ] }, @@ -464,6 +472,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215628-5gixpmp", + "style": "line-height: 22px;", "updated": "20241213215628" }, "Children": [ @@ -517,7 +526,15 @@ }, { "Type": "NodeText", - "Data": "​: この関数はデータベースをクエリしてスパンのリストを返します" + "Data": "​: この関数は" + }, + { + "Type": "NodeText", + "Data": "データベース" + }, + { + "Type": "NodeText", + "Data": "をクエリしてスパンのリストを返します" } ] }, @@ -527,6 +544,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215619-gkqs282", + "style": "line-height: 22px;", "updated": "20241224162728" }, "Children": [ @@ -580,7 +598,15 @@ }, { "Type": "NodeText", - "Data": "​: この関数はデータベースへのクエリに使用され、戻り値は結果セットです" + "Data": "​: この関数は" + }, + { + "Type": "NodeText", + "Data": "データベース" + }, + { + "Type": "NodeText", + "Data": "へのクエリに使用され、戻り値は結果セットです" } ] }, @@ -590,6 +616,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215633-69ltmv1", + "style": "line-height: 22px;", "updated": "20241213215633" }, "Children": [ @@ -653,6 +680,7 @@ "IsFencedCodeBlock": true, "Properties": { "id": "20241213215720-ueqpsna", + "style": "line-height: 22px;", "updated": "20241213215720" }, "Children": [ @@ -871,7 +899,7 @@ "Type": "NodeParagraph", "Properties": { "id": "20241212163938-y1al3b9", - "updated": "20241212163955" + "updated": "20241225192824" }, "Children": [ { @@ -881,11 +909,48 @@ { "Type": "NodeTextMark", "TextMarkType": "code", - "TextMarkTextContent": "runeLen" + "TextMarkTextContent": "runeCount" }, { "Type": "NodeText", - "Data": "​: この関数は文字列の長さを返すために使用されます" + "Data": "​: この関数は文字列内の文字数を返すために使用されます" + } + ] + } + ] + }, + { + "ID": "20241225192825-vi77q0u", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20241225192825-vi77q0u", + "updated": "20241225192831" + }, + "Children": [ + { + "ID": "20241225192825-uicespl", + "Type": "NodeParagraph", + "Properties": { + "id": "20241225192825-uicespl", + "updated": "20241225192831" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "​" + }, + { + "Type": "NodeTextMark", + "TextMarkType": "code", + "TextMarkTextContent": "wordCount" + }, + { + "Type": "NodeText", + "Data": "​:この関数は文字列内の単語数を返すために使用されます" } ] } diff --git a/kernel/filesys/template.go b/kernel/filesys/template.go index 5a69a4f2d..89d9d3df3 100644 --- a/kernel/filesys/template.go +++ b/kernel/filesys/template.go @@ -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))) }