-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.go
32 lines (28 loc) · 636 Bytes
/
markdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package golib
import (
"bytes"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
)
func RenderMarkdown(md []byte, gm goldmark.Markdown) (bs []byte, err error) {
buf := bytes.Buffer{}
err = gm.Convert(md, &buf)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func MarkdownDefault() goldmark.Markdown {
return goldmark.New(
goldmark.WithExtensions(extension.GFM),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithHardWraps(),
html.WithXHTML(),
),
)
}