diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2021-01-01 14:46:54 +0100 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2021-01-01 14:46:54 +0100 |
commit | 85473656174b1b1d6221d3bb76cc12fa5f7f7e8d (patch) | |
tree | 37349eee4f64781f06e8597dc4c457801eb03a47 /markdown | |
download | laria.me-85473656174b1b1d6221d3bb76cc12fa5f7f7e8d.tar.gz laria.me-85473656174b1b1d6221d3bb76cc12fa5f7f7e8d.tar.bz2 laria.me-85473656174b1b1d6221d3bb76cc12fa5f7f7e8d.zip |
Initial commit
Diffstat (limited to 'markdown')
-rw-r--r-- | markdown/markdown.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/markdown/markdown.go b/markdown/markdown.go new file mode 100644 index 0000000..3a4beba --- /dev/null +++ b/markdown/markdown.go @@ -0,0 +1,35 @@ +package markdown + +import ( + "bytes" + + "github.com/alecthomas/chroma/formatters/html" + "github.com/yuin/goldmark" + highlighting "github.com/yuin/goldmark-highlighting" + goldmarkHtml "github.com/yuin/goldmark/renderer/html" +) + +func Parse(s string) (string, error) { + markdown := goldmark.New( + goldmark.WithExtensions( + highlighting.NewHighlighting( + highlighting.WithStyle("monokai"), + highlighting.WithFormatOptions( + // html.WithAllClasses(true), + html.WithClasses(true), + html.WithLineNumbers(false), + ), + ), + ), + goldmark.WithRendererOptions( + goldmarkHtml.WithUnsafe(), + ), + ) + + buf := new(bytes.Buffer) + if err := markdown.Convert([]byte(s), buf); err != nil { + return "", err + } + + return buf.String(), nil +} |