30 lines
587 B
Go
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...)
|
|
}
|