Skip to content

Commit 15d87a2

Browse files
committed
text/templates: fix postline
1 parent 5319261 commit 15d87a2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

text/templates/funcs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,20 @@ var Funcs = template.FuncMap{
252252
// ```
253253
"preline": Chain(stringFunc("preline", noError(preline))),
254254

255-
// @api(Strings/blockspace) adds a newline after a string if it is not empty.
255+
// @api(Strings/postline) adds a newline after a string if it is not empty and does not end with a newline.
256256
//
257257
// Example:
258258
// ```tmpl
259-
// {{blockspace "hello"}}
260-
// {{blockspace ""}}
259+
// {{postline "hello"}}
260+
// {{postline ""}}
261261
// ```
262262
//
263263
// Output:
264264
// ```
265265
// hello
266266
//
267267
// ```
268-
"blockspace": Chain(stringFunc("blockspace", noError(blockspace))),
268+
"postline": Chain(stringFunc("postline", noError(postline))),
269269

270270
// @api(Strings/quote) returns a double-quoted string.
271271
//
@@ -1278,8 +1278,8 @@ func preline(s string) string {
12781278
return "\n" + s
12791279
}
12801280

1281-
func blockspace(s string) string {
1282-
if s == "" {
1281+
func postline(s string) string {
1282+
if s == "" || s[len(s)-1] == '\n' {
12831283
return s
12841284
}
12851285
return s + "\n"

0 commit comments

Comments
 (0)