Commit f4cbaa38 authored by Evan Kroske's avatar Evan Kroske Committed by Robert Griesemer

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
parent cac006ae
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"go/token" "go/token"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"strings" "strings"
) )
...@@ -33,10 +34,10 @@ var ( ...@@ -33,10 +34,10 @@ var (
verbose = flag.Bool("v", false, "verbose mode") verbose = flag.Bool("v", false, "verbose mode")
) )
const ( // ToHTML in comment.go assigns a (possibly blank) ID to each heading
html_h = "<h3>" var html_h = regexp.MustCompile(`<h3 id="[^"]*">`)
html_endh = "</h3>\n"
) const html_endh = "</h3>\n"
func isGoFile(fi os.FileInfo) bool { func isGoFile(fi os.FileInfo) bool {
return strings.HasSuffix(fi.Name(), ".go") && return strings.HasSuffix(fi.Name(), ".go") &&
...@@ -47,11 +48,11 @@ func appendHeadings(list []string, comment string) []string { ...@@ -47,11 +48,11 @@ func appendHeadings(list []string, comment string) []string {
var buf bytes.Buffer var buf bytes.Buffer
doc.ToHTML(&buf, comment, nil) doc.ToHTML(&buf, comment, nil)
for s := buf.String(); ; { for s := buf.String(); ; {
i := strings.Index(s, html_h) loc := html_h.FindStringIndex(s)
if i < 0 { if len(loc) == 0 {
break break
} }
i += len(html_h) i := loc[1]
j := strings.Index(s, html_endh) j := strings.Index(s, html_endh)
if j < 0 { if j < 0 {
list = append(list, s[i:]) // incorrect HTML list = append(list, s[i:]) // incorrect HTML
......
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