mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
tpl: Make chomp return template.HTML
This commit is contained in:
parent
daaf4eb330
commit
f223f17c76
2 changed files with 5 additions and 5 deletions
|
@ -1196,13 +1196,13 @@ func relRef(page interface{}, ref string) template.HTML {
|
|||
}
|
||||
|
||||
// chomp removes trailing newline characters from a string.
|
||||
func chomp(text interface{}) (string, error) {
|
||||
func chomp(text interface{}) (template.HTML, error) {
|
||||
s, err := cast.ToStringE(text)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimRight(s, "\r\n"), nil
|
||||
return template.HTML(strings.TrimRight(s, "\r\n")), nil
|
||||
}
|
||||
|
||||
// trim leading/trailing characters defined by b from a
|
||||
|
|
|
@ -63,10 +63,9 @@ func TestFuncsInTemplate(t *testing.T) {
|
|||
defer viper.Reset()
|
||||
|
||||
// Add the examples from the docs: As a smoke test and to make sure the examples work.
|
||||
// TODO(bep): Look at the use of safeHTML below; these should maybe return template.HTML
|
||||
// TODO(bep): docs: fix title example
|
||||
in :=
|
||||
`chomp: {{chomp "<p>Blockhead</p>\n" | safeHTML }}
|
||||
`chomp: {{chomp "<p>Blockhead</p>\n" }}
|
||||
dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}
|
||||
lower: {{lower "BatMan"}}
|
||||
markdownify: {{ .Title | markdownify}}
|
||||
|
@ -1643,7 +1642,8 @@ func TestChomp(t *testing.T) {
|
|||
"\r", "\r\r",
|
||||
"\r\n", "\r\n\r\n",
|
||||
} {
|
||||
chomped, _ := chomp(base + item)
|
||||
c, _ := chomp(base + item)
|
||||
chomped := string(c)
|
||||
|
||||
if chomped != base {
|
||||
t.Errorf("[%d] Chomp failed, got '%v'", i, chomped)
|
||||
|
|
Loading…
Reference in a new issue