mirror of
https://github.com/facundoolano/jorge.git
synced 2024-12-26 21:58:51 +01:00
fix xml_escape filter
This commit is contained in:
parent
b3594be86c
commit
add8a7d6c3
1 changed files with 12 additions and 14 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue