summaryrefslogtreecommitdiff
path: root/markdown/markdown.go
diff options
context:
space:
mode:
Diffstat (limited to 'markdown/markdown.go')
-rw-r--r--markdown/markdown.go35
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
+}