From e9a64f3b41b5eae47dec7c0ecfd1caae83136abc Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Sat, 20 Jul 2024 21:56:37 +0300 Subject: initial --- utils/markdown.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 utils/markdown.go (limited to 'utils/markdown.go') diff --git a/utils/markdown.go b/utils/markdown.go new file mode 100644 index 0000000..b47a02b --- /dev/null +++ b/utils/markdown.go @@ -0,0 +1,21 @@ +package utils + +import ( + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/html" + "github.com/gomarkdown/markdown/parser" +) + +func MarkdownToHTML(md string) string { + // create markdown parser with extensions + extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock + p := parser.NewWithExtensions(extensions) + doc := p.Parse([]byte(md)) + + // create HTML renderer with extensions + htmlFlags := html.CommonFlags | html.HrefTargetBlank + opts := html.RendererOptions{Flags: htmlFlags} + renderer := html.NewRenderer(opts) + + return string(markdown.Render(doc, renderer)) +} -- cgit v1.2.3