moth/pkg/transpile/markdown.go

30 lines
580 B
Go
Raw Permalink Normal View History

2021-02-25 15:56:23 -07:00
package transpile
import (
"io"
"io/ioutil"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/renderer/html"
)
// Markdown formats the provided bytes using whatever Markdown engine we're currently using.
func Markdown(input io.Reader, output io.Writer) error {
md := goldmark.New(
goldmark.WithExtensions(
extension.Table,
extension.DefinitionList,
),
goldmark.WithRendererOptions(
html.WithUnsafe(),
),
)
buf, err := ioutil.ReadAll(input)
if err != nil {
return err
}
md.Convert(buf, output)
return nil
}