diff options
author | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-07-20 21:56:37 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-07-20 21:58:27 +0300 |
commit | e9a64f3b41b5eae47dec7c0ecfd1caae83136abc (patch) | |
tree | c07898520a7015c3f2a201ca0674efea82dd76a5 /utils/markdown.go | |
parent | 9c0a6b21f8f8d9b725e1fe7f11da4532e04fd9f1 (diff) |
initialv0.0.1
Diffstat (limited to 'utils/markdown.go')
-rw-r--r-- | utils/markdown.go | 21 |
1 files changed, 21 insertions, 0 deletions
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)) +} |