1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 23:24:39 +01:00

Complete #11 cgi_escape and uri_escape

This commit is contained in:
Oliver Steele 2017-07-10 17:16:53 -04:00
parent 4f94426362
commit e0b451cf2f
3 changed files with 14 additions and 12 deletions

View File

@ -67,7 +67,7 @@ Missing features:
- Math
- CSV and JSON data files
- Plugins. (Some plugins are emulated. See the [plugin board](https://github.com/osteele/gojekyll/projects/2) for their status.)
- Template filters `group_by_exp`, `cgi_escape`, `uri_escape`, and `scssify`
- Template filters `group_by_exp` and `scssify`
- More Liquid tags and filters, listed [here](https://github.com/osteele/liquid#differences-from-liquid).
- Markdown features: [attribute lists](https://kramdown.gettalong.org/syntax.html#attribute-list-definitions), [automatic ids](https://kramdown.gettalong.org/converter/html.html#auto-ids), [`markdown=1`](https://kramdown.gettalong.org/syntax.html#html-blocks).
- `site.data` is not sorted.
@ -118,7 +118,7 @@ Muzukashii:
- [ ] Customization
- [x] Templates
- [ ] Jekyll filters
- [ ] `group_by_exp`, `cgi_escape`, `uri_escape`, `scssify`, `smartify`
- [ ] `group_by_exp` and `scssify`
- [x] everything else
- [x] Jekyll tags
- [x] `include`

View File

@ -6,6 +6,7 @@ import (
"encoding/xml"
"fmt"
"math/rand"
"net/url"
"reflect"
"regexp"
"strings"
@ -115,18 +116,15 @@ func AddJekyllFilters(e *liquid.Engine, c *config.Config) {
})
// string escapes
// engine.RegisterFilter("uri_escape", func(s string) string {
// parts := strings.SplitN(s, "?", 2)
// if len(parts) > 0 {
// TODO PathEscape is the wrong function
// parts[len(parts)-1] = url.PathEscape(parts[len(parts)-1])
// }
// return strings.Join(parts, "?")
// })
e.RegisterFilter("cgi_escape", unimplementedFilter("cgi_escape"))
e.RegisterFilter("uri_escape", unimplementedFilter("uri_escape"))
e.RegisterFilter("cgi_escape", url.QueryEscape)
e.RegisterFilter("scssify", unimplementedFilter("scssify"))
e.RegisterFilter("smartify", smartifyFilter)
e.RegisterFilter("uri_escape", func(s string) string {
return regexp.MustCompile(`\?(.+?)=([^&]*)(?:\&(.+?)=([^&]*))*`).ReplaceAllStringFunc(s, func(m string) string {
pair := strings.SplitN(m, "=", 2)
return pair[0] + "=" + url.QueryEscape(pair[1])
})
})
e.RegisterFilter("xml_escape", func(s string) string {
// TODO can't handle maps
// eval https://github.com/clbanning/mxj

View File

@ -67,8 +67,12 @@ var filterTests = []struct{ in, expected string }{
{`{{ "smartify it's they're" | smartify }}`, "smartify its theyre"},
{`{{ "smartify ... (c) (r) (tm) -- ---" | smartify }}`, "smartify … © ® ™ —"},
{`{{ "foo, bar; baz?" | cgi_escape }}`, "foo%2C+bar%3B+baz%3F"},
{`{{ "1 < 2 & 3" | xml_escape }}`, "1 &lt; 2 &amp; 3"},
// Jekyll produces the first. I believe the second is acceptable.
// {`{{ "http://foo.com/?q=foo, \bar?" | uri_escape }}`, "http://foo.com/?q=foo,%20%5Cbar?"},
{`{{ "http://foo.com/?q=foo, \bar?" | uri_escape }}`, "http://foo.com/?q=foo%2C+%5Cbar%3F"},
}
var filterTestScope = map[string]interface{}{