From acfd6d5f055ca5283dff5de16390c1d0cfc9f0ca Mon Sep 17 00:00:00 2001
From: Robert Griesemer
Date: Wed, 24 Mar 2010 16:28:59 -0700
Subject: [PATCH] godoc: show relative file names without leading '/' (per r's
request)
- change the various url-xxx formatters to return a relative URL path
- make the leading '/' for URLs explicit in the template
- on the way change some |html formatters to |html-esc
(html should only be used for formatting AST nodes)
R=rsc, r
CC=golang-dev
https://golang.org/cl/740041
---
lib/godoc/dirlist.html | 4 ++--
lib/godoc/godoc.html | 6 +++---
lib/godoc/package.html | 16 ++++++++--------
lib/godoc/search.html | 12 ++++++------
src/cmd/godoc/godoc.go | 9 +++++----
5 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/lib/godoc/dirlist.html b/lib/godoc/dirlist.html
index a94f249d91..3c1e3aae01 100644
--- a/lib/godoc/dirlist.html
+++ b/lib/godoc/dirlist.html
@@ -18,9 +18,9 @@
{.repeated section @}
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index 60a5c38641..bde1b4868b 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -692,7 +692,8 @@ func urlFmt(w io.Writer, x interface{}, format string) {
// map path
relpath := relativePath(path)
- // convert to URL
+ // convert to relative URLs so that they can also
+ // be used as relative file names in .txt templates
switch format {
default:
// we should never reach here, but be resilient
@@ -705,13 +706,13 @@ func urlFmt(w io.Writer, x interface{}, format string) {
if strings.HasPrefix(relpath, "src/pkg/") {
relpath = relpath[len("src/pkg/"):]
}
- template.HTMLEscape(w, []byte(pkgHandler.pattern+relpath))
+ template.HTMLEscape(w, []byte(pkgHandler.pattern[1:]+relpath)) // remove trailing '/' for relative URL
case "url-src":
- template.HTMLEscape(w, []byte("/"+relpath))
+ template.HTMLEscape(w, []byte(relpath))
case "url-pos":
// line id's in html-printed source are of the
// form "L%d" where %d stands for the line number
- template.HTMLEscape(w, []byte("/"+relpath))
+ template.HTMLEscape(w, []byte(relpath))
fmt.Fprintf(w, "#L%d", line)
}
}
--
2.52.0