Commit 940c25fa authored by Rob Pike's avatar Rob Pike

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
parent e77f057b
......@@ -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], "")
}
......
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