add markdownify filter

This commit is contained in:
facundoolano 2024-02-15 16:12:24 -03:00
parent ed258fddc4
commit 0906b1ef45

View file

@ -1,14 +1,17 @@
package templates
import (
"bytes"
"fmt"
"reflect"
"encoding/xml"
"time"
"github.com/osteele/liquid"
"github.com/osteele/liquid/evaluator"
"github.com/osteele/liquid/expressions"
"time"
"github.com/yuin/goldmark"
)
// a lot of the filters and tags available at jekyll aren't default liquid manually adding them here
@ -23,6 +26,16 @@ func loadJekyllFilters(e *liquid.Engine) {
e.RegisterFilter("where_exp", whereExpFilter)
e.RegisterFilter("xml_escape", xml.Marshal)
e.RegisterFilter("markdownify", func(s string) string {
// using goldmark here instead of balckfriday, to avoid an extra dependencie
var buf bytes.Buffer
err := goldmark.Convert([]byte(s), &buf)
if err != nil {
panic(err)
}
return buf.String()
})
e.RegisterFilter("absolute_url", func(s string) string {
// FIXME implement after adding a config struct, using the url
// return utils.URLJoin(c.AbsoluteURL, c.BaseURL, s)