36 lines
868 B
Go
Executable File
36 lines
868 B
Go
Executable File
package md
|
|
|
|
import (
|
|
"github.com/gomarkdown/markdown"
|
|
"github.com/gomarkdown/markdown/html"
|
|
"github.com/gomarkdown/markdown/parser"
|
|
)
|
|
|
|
func Gomarkdown(b []byte, renderHook html.RenderNodeFunc) (string, error) {
|
|
renderer := html.NewRenderer(html.RendererOptions{
|
|
Flags: html.CommonFlags | html.TOC,
|
|
RenderNodeHook: renderHook,
|
|
})
|
|
ext := parser.NoExtensions
|
|
for _, extension := range []parser.Extensions{
|
|
parser.NoIntraEmphasis,
|
|
parser.Tables,
|
|
parser.FencedCode,
|
|
parser.Autolink,
|
|
parser.Strikethrough,
|
|
parser.SpaceHeadings,
|
|
parser.HeadingIDs,
|
|
parser.BackslashLineBreak,
|
|
parser.DefinitionLists,
|
|
parser.MathJax,
|
|
parser.Titleblock,
|
|
parser.AutoHeadingIDs,
|
|
parser.Includes,
|
|
} {
|
|
ext |= extension
|
|
}
|
|
parser := parser.NewWithExtensions(ext)
|
|
content := markdown.ToHTML(b, parser, renderer)
|
|
return string(content) + "\n", nil
|
|
}
|