| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | |
| 6 | "github.com/yuin/goldmark" |
| 7 | "github.com/yuin/goldmark/extension" |
| 8 | "github.com/yuin/goldmark/parser" |
| 9 | "github.com/yuin/goldmark/renderer/html" |
| 10 | ) |
| 11 | |
| 12 | var md = goldmark.New( |
| 13 | goldmark.WithExtensions(extension.GFM, extension.Footnote), |
| 14 | goldmark.WithParserOptions(parser.WithAutoHeadingID()), |
| 15 | goldmark.WithRendererOptions(html.WithUnsafe()), |
| 16 | ) |
| 17 | |
| 18 | func renderMarkdown(src string) string { |
| 19 | var buf bytes.Buffer |
| 20 | if err := md.Convert([]byte(src), &buf); err != nil { |
| 21 | return src |
| 22 | } |
| 23 | return buf.String() |
| 24 | } |