From 85473656174b1b1d6221d3bb76cc12fa5f7f7e8d Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 1 Jan 2021 14:46:54 +0100 Subject: Initial commit --- markdown/markdown.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 markdown/markdown.go (limited to 'markdown') 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 +} -- cgit v1.2.3-70-g09d2