mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Rewrite first argument to interface{}
This commit is contained in:
parent
871e811339
commit
e08cabadb6
1 changed files with 20 additions and 2 deletions
|
@ -880,6 +880,24 @@ func Chomp(text interface{}) (string, error) {
|
||||||
return chompRegexp.ReplaceAllString(s, ""), nil
|
return chompRegexp.ReplaceAllString(s, ""), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trim leading/trailing characters defined by b from a
|
||||||
|
func Trim(a interface{}, b string) (string, error) {
|
||||||
|
aStr, err := cast.ToStringE(a)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.Trim(aStr, b), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace all occurences of b with c in a
|
||||||
|
func Replace(a interface{}, b string, c string) (string, error) {
|
||||||
|
aStr, err := cast.ToStringE(a)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.Replace(aStr, b, c, -1), nil
|
||||||
|
}
|
||||||
|
|
||||||
func SafeHtml(text string) template.HTML {
|
func SafeHtml(text string) template.HTML {
|
||||||
return template.HTML(text)
|
return template.HTML(text)
|
||||||
}
|
}
|
||||||
|
@ -1237,8 +1255,8 @@ func init() {
|
||||||
"relref": RelRef,
|
"relref": RelRef,
|
||||||
"apply": Apply,
|
"apply": Apply,
|
||||||
"chomp": Chomp,
|
"chomp": Chomp,
|
||||||
"replace": func(a string, b string, c string) string { return strings.Replace(a, b, c, -1) },
|
"replace": Replace,
|
||||||
"trim": func(a string, b string) string { return strings.Trim(a, b) },
|
"trim": Trim,
|
||||||
}
|
}
|
||||||
|
|
||||||
chompRegexp = regexp.MustCompile("[\r\n]+$")
|
chompRegexp = regexp.MustCompile("[\r\n]+$")
|
||||||
|
|
Loading…
Reference in a new issue