aboutsummaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
authorEvan Kroske <evankroske@google.com>2014-08-30 10:27:36 -0700
committerRobert Griesemer <gri@golang.org>2014-08-30 10:27:36 -0700
commitf4cbaa38aeda16bc37fa991132073a273d16cd43 (patch)
tree5fcb83a5c6bf95b7b64b0823d738fa5a0159b03c /src/pkg
parentcac006ae5a25ac333030b10b3430a4d47c8c9c19 (diff)
downloadgo-f4cbaa38aeda16bc37fa991132073a273d16cd43.tar.xz
go/doc/headscan: update script to count headings with an ID attribute
Fixes script used to sanity-check the heading-detection heuristic of go/doc. Fixes #8467. LGTM=gri R=golang-codereviews, gobot, gri CC=golang-codereviews https://golang.org/cl/128720043
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/go/doc/headscan.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pkg/go/doc/headscan.go b/src/pkg/go/doc/headscan.go
index f559347638..1ccaa15819 100644
--- a/src/pkg/go/doc/headscan.go
+++ b/src/pkg/go/doc/headscan.go
@@ -24,6 +24,7 @@ import (
"go/token"
"os"
"path/filepath"
+ "regexp"
"runtime"
"strings"
)
@@ -33,10 +34,10 @@ var (
verbose = flag.Bool("v", false, "verbose mode")
)
-const (
- html_h = "<h3>"
- html_endh = "</h3>\n"
-)
+// ToHTML in comment.go assigns a (possibly blank) ID to each heading
+var html_h = regexp.MustCompile(`<h3 id="[^"]*">`)
+
+const html_endh = "</h3>\n"
func isGoFile(fi os.FileInfo) bool {
return strings.HasSuffix(fi.Name(), ".go") &&
@@ -47,11 +48,11 @@ func appendHeadings(list []string, comment string) []string {
var buf bytes.Buffer
doc.ToHTML(&buf, comment, nil)
for s := buf.String(); ; {
- i := strings.Index(s, html_h)
- if i < 0 {
+ loc := html_h.FindStringIndex(s)
+ if len(loc) == 0 {
break
}
- i += len(html_h)
+ i := loc[1]
j := strings.Index(s, html_endh)
if j < 0 {
list = append(list, s[i:]) // incorrect HTML