diff --git a/godoc/godoc.go b/godoc/godoc.go index 7964b524..b0e721a2 100644 --- a/godoc/godoc.go +++ b/godoc/godoc.go @@ -280,6 +280,7 @@ func newPosLink_urlFunc(srcPosLinkFunc func(s string, line, low, high int) strin } func srcPosLinkFunc(s string, line, low, high int) string { + s = srcLinkFunc(s) var buf bytes.Buffer template.HTMLEscape(&buf, []byte(s)) // selection ranges are of form "s=low:high" @@ -301,7 +302,11 @@ func srcPosLinkFunc(s string, line, low, high int) string { } func srcLinkFunc(s string) string { - return pathpkg.Clean("/" + s) + s = pathpkg.Clean("/" + s) + if !strings.HasPrefix(s, "/src/pkg/") { + s = "/src/pkg" + s + } + return s } // queryLinkFunc returns a URL for a line in a source file with a highlighted diff --git a/godoc/godoc_test.go b/godoc/godoc_test.go index bf058d57..955f2f87 100644 --- a/godoc/godoc_test.go +++ b/godoc/godoc_test.go @@ -35,6 +35,8 @@ func TestSrcPosLinkFunc(t *testing.T) { {"/src/pkg/fmt/print.go", 2, 0, 0, "/src/pkg/fmt/print.go#L2"}, {"/src/pkg/fmt/print.go", 0, 0, 0, "/src/pkg/fmt/print.go"}, {"/src/pkg/fmt/print.go", 0, 1, 5, "/src/pkg/fmt/print.go?s=1:5#L1"}, + {"fmt/print.go", 0, 0, 0, "/src/pkg/fmt/print.go"}, + {"fmt/print.go", 0, 1, 5, "/src/pkg/fmt/print.go?s=1:5#L1"}, } { if got, want := srcPosLinkFunc(tc.src, tc.line, tc.low, tc.high), tc.want; got != want { t.Errorf("srcLinkFunc(%v, %v, %v, %v) = %v; want %v", tc.src, tc.line, tc.low, tc.high, got, want) @@ -49,6 +51,8 @@ func TestSrcLinkFunc(t *testing.T) { }{ {"/src/pkg/fmt/print.go", "/src/pkg/fmt/print.go"}, {"src/pkg/fmt/print.go", "/src/pkg/fmt/print.go"}, + {"/fmt/print.go", "/src/pkg/fmt/print.go"}, + {"fmt/print.go", "/src/pkg/fmt/print.go"}, } { if got, want := srcLinkFunc(tc.src), tc.want; got != want { t.Errorf("srcLinkFunc(%v) = %v; want %v", tc.src, got, want) diff --git a/godoc/static/package.html b/godoc/static/package.html index ee38396f..58d1839d 100644 --- a/godoc/static/package.html +++ b/godoc/static/package.html @@ -179,7 +179,9 @@ {{end}} {{with .PAst}} -
{{node_html $ . false}}
+ {{range $filename, $ast := .}} + {{$filename|filename|html}}:
{{node_html $ $ast false}}
+ {{end}} {{end}} {{with .Dirs}} diff --git a/godoc/static/static.go b/godoc/static/static.go index 21cb1d79..49730484 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -705,7 +705,9 @@ $(document).ready(function() { {{end}} {{with .PAst}} -
{{node_html $ . false}}
+ {{range $filename, $ast := .}} + {{$filename|filename|html}}:
{{node_html $ $ast false}}
+ {{end}} {{end}} {{with .Dirs}}