Commit 30ab8cf7 authored by Rob Pike's avatar Rob Pike

template: retain leading space if the line is not an action.

R=rsc
CC=golang-dev
https://golang.org/cl/1985042
parent 316961c1
...@@ -234,9 +234,7 @@ func (t *Template) nextItem() []byte { ...@@ -234,9 +234,7 @@ func (t *Template) nextItem() []byte {
break break
} }
} }
if trimSpace { if !trimSpace && i > start {
start = i
} else if i > start {
// white space is valid text // white space is valid text
t.p = i t.p = i
return t.buf[start:i] return t.buf[start:i]
...@@ -252,6 +250,9 @@ Switch: ...@@ -252,6 +250,9 @@ Switch:
i += len(t.ldelim) // position after delimiter i += len(t.ldelim) // position after delimiter
if i+1 < len(t.buf) && (t.buf[i] == '.' || t.buf[i] == '#') { if i+1 < len(t.buf) && (t.buf[i] == '.' || t.buf[i] == '#') {
special = true special = true
if trimSpace {
start = i - len(t.ldelim)
}
} }
for ; i < len(t.buf); i++ { for ; i < len(t.buf); i++ {
if t.buf[i] == '\n' { if t.buf[i] == '\n' {
......
...@@ -98,6 +98,7 @@ var tests = []*Test{ ...@@ -98,6 +98,7 @@ var tests = []*Test{
&Test{" {.space} \n", " ", ""}, &Test{" {.space} \n", " ", ""},
&Test{" {.tab} \n", "\t", ""}, &Test{" {.tab} \n", "\t", ""},
&Test{" {#comment} \n", "", ""}, &Test{" {#comment} \n", "", ""},
&Test{"\tSome Text\t\n", "\tSome Text\t\n", ""},
// Variables at top level // Variables at top level
&Test{ &Test{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment