summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/godoc.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-11-16 14:26:29 -0800
committerRobert Griesemer <gri@golang.org>2009-11-16 14:26:29 -0800
commitdb22261d14a6f1804dcf784c4163d5ec722d85a8 (patch)
treed876b4e7e69db46d30caee3da5b3db0ae291313c /src/cmd/godoc/godoc.go
parent2653e6d60459add75b934528a17827848ea08ec8 (diff)
downloadgolang-db22261d14a6f1804dcf784c4163d5ec722d85a8.tar.gz
Don't emit line tags when source code is printed as part of
package documentation using templates. The line tag interferes with the anchor tag introduces by the template. This fixes an an issue where some headers lost their ability to link to the respective source code. R=rsc http://codereview.appspot.com/154166
Diffstat (limited to 'src/cmd/godoc/godoc.go')
-rw-r--r--src/cmd/godoc/godoc.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index de5235673..c6f26a839 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -470,16 +470,23 @@ func parse(path string, mode uint) (*ast.File, *parseErrors) {
// Styler implements a printer.Styler.
type Styler struct {
- highlight string;
+ linetags bool;
+ highlight string;
}
// Use the defaultStyler when there is no specific styler.
+// The defaultStyler does not emit line tags since they may
+// interfere with tags emitted by templates.
+// TODO(gri): Should emit line tags at the beginning of a line;
+// never in the middle of code.
var defaultStyler Styler
func (s *Styler) LineTag(line int) (text []byte, tag printer.HTMLTag) {
- tag = printer.HTMLTag{fmt.Sprintf(`<a id="L%d">`, line), "</a>"};
+ if s.linetags {
+ tag = printer.HTMLTag{fmt.Sprintf(`<a id="L%d">`, line), "</a>"}
+ }
return;
}
@@ -932,7 +939,7 @@ func serveFile(c *http.Conn, r *http.Request) {
return;
case ext == ".go":
- serveGoSource(c, r, path, &Styler{highlight: r.FormValue("h")});
+ serveGoSource(c, r, path, &Styler{linetags: true, highlight: r.FormValue("h")});
return;
}