aboutsummaryrefslogtreecommitdiff
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
commite86afaf456b804398c100894b2467edf9716e623 (patch)
tree4ed3451521a4c48727036dc7d025763517e2e8ee
parentaffcfe5a750db21c40d6fb62c7f2ac9add818564 (diff)
downloadgo-e86afaf456b804398c100894b2467edf9716e623.tar.gz
go-e86afaf456b804398c100894b2467edf9716e623.zip
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 https://golang.org/cl/154166
-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 de52356734..c6f26a8394 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;
}