2019-03-18 13:34:52 +01:00
|
|
|
package helper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/Depado/bfchroma"
|
2022-02-28 10:27:32 +01:00
|
|
|
"github.com/russross/blackfriday/v2"
|
2019-03-18 13:34:52 +01:00
|
|
|
)
|
|
|
|
|
2019-03-19 12:46:32 +01:00
|
|
|
// RenderMarkdown renders input to html with chroma syntax highlighting if wanted
|
2019-03-18 13:34:52 +01:00
|
|
|
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...)
|
|
|
|
}
|