mark2web/filter/markdown.go
Sebastian Frank 29f01a2618
All checks were successful
continuous-integration/drone/push Build is passing
reorganized code
2019-03-18 15:14:41 +01:00

30 lines
715 B
Go

package filter
import (
"gitbase.de/apairon/mark2web"
"gitbase.de/apairon/mark2web/helper"
"github.com/flosch/pongo2"
)
// MarkdownFilter is a pongo2 filter, which converts markdown to html
func MarkdownFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
chromaRenderer := false
chromaStyle := "monokai"
if m := mark2web.CurrentPathConfig.Markdown; m != nil {
if m.ChromaRenderer != nil && *m.ChromaRenderer {
chromaRenderer = true
}
if m.ChromaStyle != nil && *m.ChromaStyle != "" {
chromaStyle = *m.ChromaStyle
}
}
return pongo2.AsSafeValue(
string(
helper.RenderMarkdown(
[]byte(in.String()),
chromaRenderer,
chromaStyle,
))),
nil
}