From 940c25faa4e495a13d6411fe23640c9d16b1e986 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 9 Dec 2011 08:31:04 -0800 Subject: [PATCH] tmpltohtml: feature for easier snippet extraction Lines that end with OMIT are omitted from the output. A comment such as // Example stops here. OMIT can be used as a marker but not appear in the output. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5477050 --- doc/tmpltohtml.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/tmpltohtml.go b/doc/tmpltohtml.go index 84a47d6ed2b..ab8e490bf21 100644 --- a/doc/tmpltohtml.go +++ b/doc/tmpltohtml.go @@ -16,7 +16,13 @@ // {{code "foo.go" `/^func.main/` `/^}/` // // Patterns can be `/regular expression/`, a decimal number, or "$" -// to signify the end of the file. +// to signify the end of the file. In multi-line matches, +// lines that end with the four characters +// OMIT +// are omitted from the output, making it easy to provide marker +// lines in the input that will not appear in the output but are easy +// to identify by pattern. + package main import ( @@ -153,6 +159,11 @@ func multipleLines(file, text string, arg1, arg2 interface{}) string { } else if line2 < line1 { log.Fatalf("lines out of order for %q: %d %d", text, line1, line2) } + for k := line1 - 1; k < line2; k++ { + if strings.HasSuffix(lines[k], "OMIT\n") { + lines[k] = "" + } + } return strings.Join(lines[line1-1:line2], "") }