package main import ( "fmt" "github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown/html" "github.com/gomarkdown/markdown/parser" ) var mds = `# header Sample text. [link](http://example.com) ` func mdToHTML(md []byte) []byte { extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock p := parser.NewWithExtensions(extensions) doc := p.Parse(md) htmlFlags := html.CommonFlags | html.HrefTargetBlank opts := html.RendererOptions{Flags: htmlFlags} renderer := html.NewRenderer(opts) return markdown.Render(doc, renderer) } func main() { md := []byte(mds) html := mdToHTML(md) fmt.Printf("--- Markdown:\n%s\n\n--- HTML:\n%s\n", md, html) }