doc/go_spec.html | 3 ++- doc/style.css | 5 +++++ lib/godoc/godoc.html | 9 ++++++++- src/cmd/godoc/godoc.go | 42 ++++++++++++++++++++++++++---------------- src/cmd/godoc/main.go | 2 +- diff --git a/doc/go_spec.html b/doc/go_spec.html index 003bbdc03a5bf669ed94fb5cfba0522ec68a53be..84480f6e8a9f224a976bf0288cd906460a48c0b2 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,4 +1,5 @@ - + + +

{Content} diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 62265cf6a8a7f84d74776a2dcfb04e11f4cdfd52..f302f8c7e9a9e29b205ad334e51cf2814a5ca348 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -19,6 +19,7 @@ "io/ioutil" "log" "os" pathutil "path" + "regexp" "runtime" "strings" "sync" @@ -874,9 +875,10 @@ // ---------------------------------------------------------------------------- // Generic HTML wrapper -func servePage(c *http.Conn, title, query string, content []byte) { +func servePage(c *http.Conn, title, subtitle, query string, content []byte) { type Data struct { Title string + Subtitle string PkgRoots []string Timestamp uint64 // int64 to be compatible with os.Dir.Mtime_ns Query string @@ -888,6 +890,7 @@ _, ts := fsTree.get() d := Data{ Title: title, + Subtitle: subtitle, PkgRoots: fsMap.PrefixList(), Timestamp: uint64(ts) * 1e9, // timestamp in ns Query: query, @@ -912,16 +915,16 @@ // ---------------------------------------------------------------------------- // Files var ( - tagBegin = []byte("") + titleRx = regexp.MustCompile(``) + subtitleRx = regexp.MustCompile(``) + firstCommentRx = regexp.MustCompile(``) ) -// commentText returns the text of the first HTML comment in src. -func commentText(src []byte) (text string) { - i := bytes.Index(src, tagBegin) - j := bytes.Index(src, tagEnd) - if i >= 0 && j >= i+len(tagBegin) { - text = string(bytes.TrimSpace(src[i+len(tagBegin) : j])) + +func extractString(src []byte, rx *regexp.Regexp) (s string) { + m := rx.Execute(src) + if len(m) >= 4 { + s = strings.TrimSpace(string(src[m[2]:m[3]])) } return } @@ -950,8 +953,15 @@ linkify(&buf, src) src = buf.Bytes() } - title := commentText(src) - servePage(c, title, "", src) + // get title and subtitle, if any + title := extractString(src, titleRx) + if title == "" { + // no title found; try first comment for backward-compatibility + title = extractString(src, firstCommentRx) + } + subtitle := extractString(src, subtitleRx) + + servePage(c, title, subtitle, "", src) } @@ -983,7 +993,7 @@ } info := &SourceInfo{buf.Bytes(), styler.mapping()} contents := applyTemplate(sourceHTML, "sourceHTML", info) - servePage(c, "Source file "+relpath, "", contents) + servePage(c, "Source file "+relpath, "", "", contents) } @@ -1056,7 +1066,7 @@ fmt.Fprintln(&buf, "
")
 	template.HTMLEscape(&buf, src)
 	fmt.Fprintln(&buf, "
") - servePage(c, "Text file "+relpath, "", buf.Bytes()) + servePage(c, "Text file "+relpath, "", "", buf.Bytes()) } @@ -1079,7 +1089,7 @@ } } contents := applyTemplate(dirlistHTML, "dirlistHTML", list) - servePage(c, "Directory "+relpath, "", contents) + servePage(c, "Directory "+relpath, "", "", contents) } @@ -1326,7 +1336,7 @@ title = "Directory " + relativePath(info.Dirname) } contents := applyTemplate(packageHTML, "packageHTML", info) - servePage(c, title, "", contents) + servePage(c, title, "", "", contents) } @@ -1373,7 +1383,7 @@ title = fmt.Sprintf(`No results found for query %q`, query) } contents := applyTemplate(searchHTML, "searchHTML", result) - servePage(c, title, query, contents) + servePage(c, title, "", query, contents) } diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go index 0ede0dcc949f509a34052812aefd2161100db423..7a9279a2f4261ed5a6ec311b84e09980cdb6ab21 100644 --- a/src/cmd/godoc/main.go +++ b/src/cmd/godoc/main.go @@ -66,7 +66,7 @@ func serveError(c *http.Conn, r *http.Request, relpath string, err os.Error) { contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path! - servePage(c, "File "+relpath, "", contents) + servePage(c, "File "+relpath, "", "", contents) }