mark2web/filter/markdown.go

30 lines
715 B
Go
Raw Normal View History

2019-03-18 13:34:52 +01:00
package filter
import (
2019-03-18 15:14:41 +01:00
"gitbase.de/apairon/mark2web"
2019-03-18 13:34:52 +01:00
"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"
2019-03-18 15:14:41 +01:00
if m := mark2web.CurrentPathConfig.Markdown; m != nil {
2019-03-18 13:34:52 +01:00
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
}