}
}
-// 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 {
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 ""
{"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},
{"'sX", false},
{"Ted 'Too' Bar", false},
{"Use n+m", false},
- {"Scanning:", true},
+ {"Scanning:", false},
{"N:M", false},
}