fix xml_escape filter

This commit is contained in:
facundoolano 2024-02-25 11:35:08 -03:00
parent b3594be86c
commit add8a7d6c3

View file

@ -3,7 +3,6 @@ package templates
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"net/url" "net/url"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -33,29 +32,28 @@ func loadJekyllFilters(e *liquid.Engine, siteUrl string, includesDir string) {
e.RegisterFilter("keys", keysFilter) e.RegisterFilter("keys", keysFilter)
e.RegisterFilter("where", whereFilter) e.RegisterFilter("where", whereFilter)
e.RegisterFilter("where_exp", whereExpFilter) e.RegisterFilter("where_exp", whereExpFilter)
e.RegisterFilter("xml_escape", xml.Marshal)
e.RegisterFilter("normalize_whitespace", func(s string) string { e.RegisterFilter("normalize_whitespace", func(s string) string {
wsPattern := regexp.MustCompile(`(?s:[\s\n]+)`) wsPattern := regexp.MustCompile(`(?s:[\s\n]+)`)
return wsPattern.ReplaceAllString(s, " ") return wsPattern.ReplaceAllString(s, " ")
}) })
e.RegisterFilter("markdownify", func(s string) string { e.RegisterFilter("markdownify", func(s string) (string, error) {
// using goldmark here instead of balckfriday, to avoid an extra dependencie // using goldmark here instead of balckfriday, to avoid an extra dependency
var buf bytes.Buffer var buf bytes.Buffer
err := goldmark.Convert([]byte(s), &buf) err := goldmark.Convert([]byte(s), &buf)
if err != nil { return buf.String(), err
log.Fatal(err)
}
return buf.String()
}) })
e.RegisterFilter("absolute_url", func(path string) string { e.RegisterFilter("xml_escape", func(s string) (string, error) {
url, err := url.JoinPath(siteUrl, path) // using goldmark here instead of balckfriday, to avoid an extra dependency
if err != nil { var buf bytes.Buffer
log.Fatal(err) err := xml.EscapeText(&buf, []byte(s))
} return buf.String(), err
return url })
e.RegisterFilter("absolute_url", func(path string) (string, error) {
return url.JoinPath(siteUrl, path)
}) })
e.RegisterFilter("date_to_rfc822", func(date time.Time) string { e.RegisterFilter("date_to_rfc822", func(date time.Time) string {