]> Cypherpunks repositories - gostls13.git/commit
text/template: provide a way to trim leading and trailing space between actions
authorRob Pike <r@golang.org>
Tue, 8 Sep 2015 21:58:12 +0000 (14:58 -0700)
committerRob Pike <r@golang.org>
Wed, 9 Sep 2015 05:28:11 +0000 (05:28 +0000)
commite6ee26a03b79d0e8b658463bdb29349ca68e1460
tree3c8ba47d66ba2ba5d9d00675a1fb67de8b4ebd08
parent49fb8cc10c2d61ebdf3829f42bba9bec7b0a7ff7
text/template: provide a way to trim leading and trailing space between actions

Borrowing a suggestion from the issue listed below, we modify the lexer to
trim spaces at the beginning (end) of a block of text if the action immediately
before (after) is marked with a minus sign. To avoid parsing/lexing ambiguity,
we require an ASCII space between the minus sign and the rest of the action.
Thus:

{{23 -}}
<
{{- 45}}

produces the output
23<45

All the work is done in the lexer. The modification is invisible to the parser
or any outside package (except I guess for noticing some gaps in the input
if one tracks error positions). Thus it slips in without worry in text/template
and html/template both.

Fixes long-requested issue #9969.

Change-Id: I3774be650bfa6370cb993d0899aa669c211de7b2
Reviewed-on: https://go-review.googlesource.com/14391
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/text/template/doc.go
src/text/template/example_test.go
src/text/template/exec_test.go
src/text/template/parse/lex.go
src/text/template/parse/lex_test.go
src/text/template/parse/parse_test.go