1
0
mirror of https://github.com/golang/go synced 2024-11-25 08:57:58 -07:00

go/doc: exclude lines ending in ':' from possible headings

This is a more conservative approach to heading detection and
removes 11 headings from the current repository (several in
fmt). The current headscan output is:

/home/gri/go3/src/cmd/goinstall (package documentation)
        Remote Repositories
        The GOPATH Environment Variable
/home/gri/go3/src/pkg/exp/gotype (package documentation)
        Examples
/home/gri/go3/src/pkg/html/template (package template)
        Introduction
        Contexts
        Errors
        A fuller picture
        Contexts
        Typed Strings
        Security Model
/home/gri/go3/src/pkg/text/template (package template)
        Actions
        Arguments
        Pipelines
        Variables
        Examples
        Functions
        Associated templates
        Nested template definitions
18 headings found

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/5437105
This commit is contained in:
Robert Griesemer 2011-12-01 15:14:15 -08:00
parent 1e5aecf6ce
commit 6ea3a268b6
2 changed files with 7 additions and 11 deletions

View File

@ -241,8 +241,8 @@ func unindent(block []string) {
} }
} }
// heading returns the (possibly trimmed) line if it passes as a valid section // heading returns the trimmed line if it passes as a section heading;
// heading; otherwise it returns the empty string. // otherwise it returns the empty string.
func heading(line string) string { func heading(line string) string {
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if len(line) == 0 { if len(line) == 0 {
@ -255,17 +255,12 @@ func heading(line string) string {
return "" return ""
} }
// it must end in a letter, digit or ':' // it must end in a letter or digit:
r, _ = utf8.DecodeLastRuneInString(line) r, _ = utf8.DecodeLastRuneInString(line)
if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != ':' { if !unicode.IsLetter(r) && !unicode.IsDigit(r) {
return "" return ""
} }
// strip trailing ':', if any
if r == ':' {
line = line[0 : len(line)-1]
}
// exclude lines with illegal characters // exclude lines with illegal characters
if strings.IndexAny(line, ",.;:!?+*/=()[]{}_^°&§~%#@<\">\\") >= 0 { if strings.IndexAny(line, ",.;:!?+*/=()[]{}_^°&§~%#@<\">\\") >= 0 {
return "" return ""

View File

@ -18,7 +18,8 @@ var headingTests = []struct {
{"Foo 42", true}, {"Foo 42", true},
{"", false}, {"", false},
{"section", false}, {"section", false},
{"A typical usage:", true}, {"A typical usage:", false},
{"This code:", false},
{"δ is Greek", false}, {"δ is Greek", false},
{"Foo §", false}, {"Foo §", false},
{"Fermat's Last Sentence", true}, {"Fermat's Last Sentence", true},
@ -26,7 +27,7 @@ var headingTests = []struct {
{"'sX", false}, {"'sX", false},
{"Ted 'Too' Bar", false}, {"Ted 'Too' Bar", false},
{"Use n+m", false}, {"Use n+m", false},
{"Scanning:", true}, {"Scanning:", false},
{"N:M", false}, {"N:M", false},
} }