From 0906b1ef45b0e81d94f7f13382ea82f5443145f0 Mon Sep 17 00:00:00 2001 From: facundoolano Date: Thu, 15 Feb 2024 16:12:24 -0300 Subject: [PATCH] add markdownify filter --- templates/filters.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/filters.go b/templates/filters.go index fd36902..56699f0 100644 --- a/templates/filters.go +++ b/templates/filters.go @@ -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)