-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
51 lines (46 loc) · 1.12 KB
/
services.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package services
import (
"bytes"
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/yuin/goldmark"
highlighting "github.com/yuin/goldmark-highlighting/v2"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
"go.abhg.dev/goldmark/anchor"
)
func markdownToHTML(md []byte) []byte {
parser := goldmark.New(
goldmark.WithParserOptions(
parser.WithAutoHeadingID(), // read note
),
goldmark.WithExtensions(
extension.Table,
extension.Strikethrough,
extension.Linkify,
extension.TaskList,
extension.DefinitionList,
extension.Footnote,
extension.Typographer,
highlighting.NewHighlighting(
highlighting.WithStyle("xcode-dark"),
highlighting.WithFormatOptions(
chromahtml.WithLineNumbers(true),
),
),
&anchor.Extender{
Texter: anchor.Text("🔗"),
Position: anchor.Before,
},
),
goldmark.WithRendererOptions(
html.WithUnsafe(),
),
)
// create markdown parser with extensions
var buf bytes.Buffer
if err := parser.Convert(md, &buf); err != nil {
panic(err)
}
return buf.Bytes()
}