From 9384d34c58099657bb1b133beaf3ff37ada9b017 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 10 Sep 2020 18:53:26 -0400 Subject: text/template: allow newlines inside action delimiters This allows multiline constructs like: {{"hello" | printf}} Now that unclosed actions can span multiple lines, track and report the start of the action when reporting errors. Also clean up a few "unexpected " to be just "". Fixes #29770. Change-Id: I54c6c016029a8328b7902a4b6d85eab713ec3285 Reviewed-on: https://go-review.googlesource.com/c/go/+/254257 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Go Bot Reviewed-by: Rob Pike --- src/text/template/doc.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/text/template/doc.go') diff --git a/src/text/template/doc.go b/src/text/template/doc.go index 4b0efd2df8..7b30294336 100644 --- a/src/text/template/doc.go +++ b/src/text/template/doc.go @@ -40,16 +40,17 @@ More intricate examples appear below. Text and spaces By default, all text between actions is copied verbatim when the template is -executed. For example, the string " items are made of " in the example above appears -on standard output when the program is run. - -However, to aid in formatting template source code, if an action's left delimiter -(by default "{{") is followed immediately by a minus sign and ASCII space character -("{{- "), all trailing white space is trimmed from the immediately preceding text. -Similarly, if the right delimiter ("}}") is preceded by a space and minus sign -(" -}}"), all leading white space is trimmed from the immediately following text. -In these trim markers, the ASCII space must be present; "{{-3}}" parses as an -action containing the number -3. +executed. For example, the string " items are made of " in the example above +appears on standard output when the program is run. + +However, to aid in formatting template source code, if an action's left +delimiter (by default "{{") is followed immediately by a minus sign and white +space, all trailing white space is trimmed from the immediately preceding text. +Similarly, if the right delimiter ("}}") is preceded by white space and a minus +sign, all leading white space is trimmed from the immediately following text. +In these trim markers, the white space must be present: +"{{- 3}}" is like "{{3}}" but trims the immediately preceding text, while +"{{-3}}" parses as an action containing the number -3. For instance, when executing the template whose source is -- cgit v1.3