mirror of
https://github.com/golang/go
synced 2024-11-21 17:34:40 -07:00
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
This commit is contained in:
parent
e77f057bf3
commit
940c25faa4
@ -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], "")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user