Commit 6ea3a268 authored by Robert Griesemer's avatar Robert Griesemer

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
parent 1e5aecf6
......@@ -241,8 +241,8 @@ func unindent(block []string) {
}
}
// heading returns the (possibly trimmed) line if it passes as a valid section
// heading; otherwise it returns the empty string.
// heading returns the trimmed line if it passes as a section heading;
// otherwise it returns the empty string.
func heading(line string) string {
line = strings.TrimSpace(line)
if len(line) == 0 {
......@@ -255,17 +255,12 @@ func heading(line string) string {
return ""
}
// it must end in a letter, digit or ':'
// it must end in a letter or digit:
r, _ = utf8.DecodeLastRuneInString(line)
if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != ':' {
if !unicode.IsLetter(r) && !unicode.IsDigit(r) {
return ""
}
// strip trailing ':', if any
if r == ':' {
line = line[0 : len(line)-1]
}
// exclude lines with illegal characters
if strings.IndexAny(line, ",.;:!?+*/=()[]{}_^°&§~%#@<\">\\") >= 0 {
return ""
......
......@@ -18,7 +18,8 @@ var headingTests = []struct {
{"Foo 42", true},
{"", false},
{"section", false},
{"A typical usage:", true},
{"A typical usage:", false},
{"This code:", false},
{"δ is Greek", false},
{"Foo §", false},
{"Fermat's Last Sentence", true},
......@@ -26,7 +27,7 @@ var headingTests = []struct {
{"'sX", false},
{"Ted 'Too' Bar", false},
{"Use n+m", false},
{"Scanning:", true},
{"Scanning:", false},
{"N:M", false},
}
......
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