- commit
- 02808fb
- parent
- 5d6d483
- author
- Eric Bower
- date
- 2024-03-21 18:56:50 +0000 UTC
cleanup
1 files changed,
+16,
-22
1@@ -171,6 +171,20 @@ func toTags(obj interface{}) ([]string, error) {
2 return arr, nil
3 }
4
5+func CreateGoldmark(extenders ...goldmark.Extender) goldmark.Markdown {
6+ return goldmark.New(
7+ goldmark.WithExtensions(
8+ extenders...,
9+ ),
10+ goldmark.WithParserOptions(
11+ parser.WithAutoHeadingID(),
12+ ),
13+ goldmark.WithRendererOptions(
14+ ghtml.WithUnsafe(),
15+ ),
16+ )
17+}
18+
19 func ParseText(text string) (*ParsedText, error) {
20 parsed := ParsedText{
21 MetaData: &MetaData{
22@@ -195,17 +209,7 @@ func ParseText(text string) (*ParsedText, error) {
23 Texter: anchor.Text("#"),
24 },
25 }
26- md := goldmark.New(
27- goldmark.WithExtensions(
28- extenders...,
29- ),
30- goldmark.WithParserOptions(
31- parser.WithAutoHeadingID(),
32- ),
33- goldmark.WithRendererOptions(
34- ghtml.WithUnsafe(),
35- ),
36- )
37+ md := CreateGoldmark(extenders...)
38 context := parser.NewContext()
39 // we do the Parse/Render steps manually to get a chance to examine the AST
40 btext := []byte(text)
41@@ -225,17 +229,7 @@ func ParseText(text string) (*ParsedText, error) {
42 TitleID: "toc",
43 ListID: "toc-list",
44 })
45- md = goldmark.New(
46- goldmark.WithExtensions(
47- extenders...,
48- ),
49- goldmark.WithParserOptions(
50- parser.WithAutoHeadingID(),
51- ),
52- goldmark.WithRendererOptions(
53- ghtml.WithUnsafe(),
54- ),
55- )
56+ md = CreateGoldmark(extenders...)
57 context := parser.NewContext()
58 doc = md.Parser().Parse(gtext.NewReader(btext), parser.WithContext(context))
59 }