mirror of
https://github.com/golang/go
synced 2024-11-13 17:00:22 -07:00
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
This commit is contained in:
parent
affcfe5a75
commit
e86afaf456
@ -470,16 +470,23 @@ func parse(path string, mode uint) (*ast.File, *parseErrors) {
|
|||||||
|
|
||||||
// Styler implements a printer.Styler.
|
// Styler implements a printer.Styler.
|
||||||
type Styler struct {
|
type Styler struct {
|
||||||
highlight string;
|
linetags bool;
|
||||||
|
highlight string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Use the defaultStyler when there is no specific styler.
|
// 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
|
var defaultStyler Styler
|
||||||
|
|
||||||
|
|
||||||
func (s *Styler) LineTag(line int) (text []byte, tag printer.HTMLTag) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -932,7 +939,7 @@ func serveFile(c *http.Conn, r *http.Request) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case ext == ".go":
|
case ext == ".go":
|
||||||
serveGoSource(c, r, path, &Styler{highlight: r.FormValue("h")});
|
serveGoSource(c, r, path, &Styler{linetags: true, highlight: r.FormValue("h")});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user