]> Cypherpunks repositories - gostls13.git/commitdiff
tmpltohtml: feature for easier snippet extraction
authorRob Pike <r@golang.org>
Fri, 9 Dec 2011 16:31:04 +0000 (08:31 -0800)
committerRob Pike <r@golang.org>
Fri, 9 Dec 2011 16:31:04 +0000 (08:31 -0800)
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

index 84a47d6ed2bd8b00849534e2350b81642ebe77ae..ab8e490bf21024e447f79e28caa0234e8fe7abbf 100644 (file)
 //     {{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], "")
 }