mark2web/pkg/helper/markdown.go
Sebastian Frank 70d7497eda
All checks were successful
continuous-integration/drone/push Build is passing
better project layout
2019-03-19 11:15:32 +01:00

30 lines
587 B
Go

package helper
import (
"bytes"
"github.com/Depado/bfchroma"
"gopkg.in/russross/blackfriday.v2"
)
func RenderMarkdown(input []byte, chromaRenderer bool, chromaStyle string) []byte {
var options []blackfriday.Option
if chromaStyle == "" {
chromaStyle = "monokai"
}
if chromaRenderer {
options = []blackfriday.Option{
blackfriday.WithRenderer(
bfchroma.NewRenderer(
bfchroma.Style(chromaStyle),
),
),
}
}
// fix \r from markdown for blackfriday
input = bytes.Replace(input, []byte("\r"), []byte(""), -1)
return blackfriday.Run(input, options...)
}