mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 New template functions markdown2text and markdown2content https://github.com/siyuan-note/siyuan/issues/13880
This commit is contained in:
parent
eaeb2558c8
commit
74bf7adbb3
1 changed files with 23 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/go-humanize"
|
"github.com/88250/go-humanize"
|
||||||
|
"github.com/88250/lute/parse"
|
||||||
util2 "github.com/88250/lute/util"
|
util2 "github.com/88250/lute/util"
|
||||||
"github.com/Masterminds/sprig/v3"
|
"github.com/Masterminds/sprig/v3"
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
|
|
@ -53,9 +54,31 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
|
||||||
ret["statBlock"] = StatBlock
|
ret["statBlock"] = StatBlock
|
||||||
ret["runeCount"] = runeCount
|
ret["runeCount"] = runeCount
|
||||||
ret["wordCount"] = wordCount
|
ret["wordCount"] = wordCount
|
||||||
|
ret["markdown2text"] = markdown2text
|
||||||
|
ret["markdown2content"] = markdown2content
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func markdown2content(md string) (ret string) {
|
||||||
|
luteEngine := util.NewLute()
|
||||||
|
tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
|
||||||
|
if nil == tree || nil == tree.Root {
|
||||||
|
logging.LogWarnf("parse markdown [%s] failed", md)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return tree.Root.Content()
|
||||||
|
}
|
||||||
|
|
||||||
|
func markdown2text(md string) (ret string) {
|
||||||
|
luteEngine := util.NewLute()
|
||||||
|
tree := parse.Parse("", []byte(md), luteEngine.ParseOptions)
|
||||||
|
if nil == tree || nil == tree.Root {
|
||||||
|
logging.LogWarnf("parse markdown [%s] failed", md)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return tree.Root.Text()
|
||||||
|
}
|
||||||
|
|
||||||
func runeCount(s string) (ret int) {
|
func runeCount(s string) (ret int) {
|
||||||
ret, _ = util2.WordCount(s)
|
ret, _ = util2.WordCount(s)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue