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 @} - {Name|html}{@|dir/} + {Name|html-esc}{@|dir/} - {Size|html} + {Size|html-esc} {Mtime_ns|time} diff --git a/lib/godoc/godoc.html b/lib/godoc/godoc.html index f41b46a273..99cd55eae6 100644 --- a/lib/godoc/godoc.html +++ b/lib/godoc/godoc.html @@ -4,7 +4,7 @@ - {Title|html} + {Title|html-esc} @@ -121,7 +121,7 @@
  •  
  • {Timestamp|time}
  • -
  • Build version {Version|html}
  • +
  • Build version {Version|html-esc}
  • @@ -133,7 +133,7 @@ {.end} -

    {Title|html}

    +

    {Title|html-esc}

    diff --git a/lib/godoc/package.html b/lib/godoc/package.html index d0a5970b38..0eff78e45c 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -12,7 +12,7 @@ {.section PDoc} {.section IsPkg} -

    import "{ImportPath|html}"

    +

    import "{ImportPath|html-esc}"

    {.end} {Doc|html-comment} {.section IsPkg} @@ -21,7 +21,7 @@

    Package files

    {.repeated section @} - {@|localname} + {@|localname} {.end}

    @@ -43,14 +43,14 @@ {.end} {.section Funcs} {.repeated section @} -

    func {Name|html}

    +

    func {Name|html-esc}

    {Decl|html}

    {Doc|html-comment} {.end} {.end} {.section Types} {.repeated section @} -

    type {Type.Name|html}

    +

    type {Type.Name|html-esc}

    {Doc|html-comment}

    {Decl|html}

    {.repeated section Consts} @@ -62,12 +62,12 @@
    {Decl|html}
    {.end} {.repeated section Factories} -

    func {Name|html}

    +

    func {Name|html-esc}

    {Decl|html}

    {Doc|html-comment} {.end} {.repeated section Methods} -

    func ({Recv|html}) {Name|html}

    +

    func ({Recv|html}) {Name|html-esc}

    {Decl|html}

    {Doc|html-comment} {.end} @@ -103,9 +103,9 @@ {.repeated section List} {Depth|padding} - {Name|html} + {Name|html-esc} - {Synopsis|html} + {Synopsis|html-esc} {.end} diff --git a/lib/godoc/search.html b/lib/godoc/search.html index 3d417aa271..febd7e5693 100644 --- a/lib/godoc/search.html +++ b/lib/godoc/search.html @@ -14,7 +14,7 @@

    Did you mean: {.repeated section Alts} - {@|html} + {@|html-esc} {.end}

    {.end} @@ -22,11 +22,11 @@ {.section Decls}

    Package-level declarations

    {.repeated section @} -

    package {Pak.Name|html}

    +

    package {Pak.Name|html-esc}

    {.repeated section Files} {.repeated section Groups} {.repeated section Infos} - {File.Path|url-src}:{@|infoLine} + {File.Path|url-src}:{@|infoLine}
    {@|infoSnippet}
    {.end} {.end} @@ -36,9 +36,9 @@ {.section Others}

    Local declarations and uses

    {.repeated section @} -

    package {Pak.Name|html}

    +

    package {Pak.Name|html-esc}

    {.repeated section Files} - {File.Path|url-src} + {File.Path|url-src} {.repeated section Groups} @@ -47,7 +47,7 @@ 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) } }
    {.repeated section Infos} - {@|infoLine} + {@|infoLine} {.end}