@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
"github.com/88250/go-humanize"
25
+ "github.com/88250/lute/parse"
25
26
util2 "github.com/88250/lute/util"
26
27
"github.com/Masterminds/sprig/v3"
27
28
"github.com/araddon/dateparse"
@@ -53,9 +54,31 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
53
54
ret ["statBlock" ] = StatBlock
54
55
ret ["runeCount" ] = runeCount
55
56
ret ["wordCount" ] = wordCount
57
+ ret ["markdown2text" ] = markdown2text
58
+ ret ["markdown2content" ] = markdown2content
56
59
return
57
60
}
58
61
62
+ func markdown2content (md string ) (ret string ) {
63
+ luteEngine := util .NewLute ()
64
+ tree := parse .Parse ("" , []byte (md ), luteEngine .ParseOptions )
65
+ if nil == tree || nil == tree .Root {
66
+ logging .LogWarnf ("parse markdown [%s] failed" , md )
67
+ return
68
+ }
69
+ return tree .Root .Content ()
70
+ }
71
+
72
+ func markdown2text (md string ) (ret string ) {
73
+ luteEngine := util .NewLute ()
74
+ tree := parse .Parse ("" , []byte (md ), luteEngine .ParseOptions )
75
+ if nil == tree || nil == tree .Root {
76
+ logging .LogWarnf ("parse markdown [%s] failed" , md )
77
+ return
78
+ }
79
+ return tree .Root .Text ()
80
+ }
81
+
59
82
func runeCount (s string ) (ret int ) {
60
83
ret , _ = util2 .WordCount (s )
61
84
return
0 commit comments