]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: show relative file names without leading '/' (per r's request)
authorRobert Griesemer <gri@golang.org>
Wed, 24 Mar 2010 23:28:59 +0000 (16:28 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 24 Mar 2010 23:28:59 +0000 (16:28 -0700)
- 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
lib/godoc/godoc.html
lib/godoc/package.html
lib/godoc/search.html
src/cmd/godoc/godoc.go

index a94f249d91f87e34ac79ce399f6d2b39d92c4cd5..3c1e3aae01bb3d48db54dbe45d845054bb0d4a20 100644 (file)
@@ -18,9 +18,9 @@
 </tr>
 {.repeated section @}
 <tr>
-       <td align="left"><a href="{Name|html-esc}{@|dir/}">{Name|html}{@|dir/}</a></td>
+       <td align="left"><a href="{Name|html-esc}{@|dir/}">{Name|html-esc}{@|dir/}</a></td>
        <td></td>
-       <td align="right">{Size|html}</td>
+       <td align="right">{Size|html-esc}</td>
        <td></td>
        <td align="left">{Mtime_ns|time}</td>
 </tr>
index f41b46a2737b6ba4bc67541b56fc079932cc23ea..99cd55eae68c6a78ed6a88e4e9033d4cba9a7138 100644 (file)
@@ -4,7 +4,7 @@
 <head>
 
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
-  <title>{Title|html}</title>
+  <title>{Title|html-esc}</title>
 
   <link rel="stylesheet" type="text/css" href="/doc/style.css">
   <script type="text/javascript" src="/doc/godocs.js"></script>
     <li class="blank">&nbsp;</li>
     <li class="navhead">Last update</li>
        <li>{Timestamp|time}</li>
-       <li>Build version {Version|html}</li>
+       <li>Build version {Version|html-esc}</li>
   </ul>
 </div>
 
     </div>
   {.end}
 
-  <h1 id="generatedHeader">{Title|html}</h1>
+  <h1 id="generatedHeader">{Title|html-esc}</h1>
 
   <!-- The Table of Contents is automatically inserted in this <div>.
        Do not delete this <div>. -->
index d0a5970b38d0b26c2832433b8b8719668fc4552a..0eff78e45cea17c11a0c961bfb8a27876730424d 100644 (file)
@@ -12,7 +12,7 @@
 {.section PDoc}
        <!-- PackageName is printed as title by the top-level template -->
        {.section IsPkg}
-               <p><code>import "{ImportPath|html}"</code></p>
+               <p><code>import "{ImportPath|html-esc}"</code></p>
        {.end}
        {Doc|html-comment}
        {.section IsPkg}
@@ -21,7 +21,7 @@
                        <h4>Package files</h4>
                        <span style="font-size:90%">
                        {.repeated section @}
-                               <a href="{@|url-src}">{@|localname}</a>
+                               <a href="/{@|url-src}">{@|localname}</a>
                        {.end}
                        </span>
                        </p>
        {.end}
        {.section Funcs}
                {.repeated section @}
-                       <h2 id="{Name|html-esc}">func <a href="{Decl|url-pos}">{Name|html}</a></h2>
+                       <h2 id="{Name|html-esc}">func <a href="/{Decl|url-pos}">{Name|html-esc}</a></h2>
                        <p><code>{Decl|html}</code></p>
                        {Doc|html-comment}
                {.end}
        {.end}
        {.section Types}
                {.repeated section @}
-                       <h2 id="{Type.Name|html-esc}">type <a href="{Decl|url-pos}">{Type.Name|html}</a></h2>
+                       <h2 id="{Type.Name|html-esc}">type <a href="/{Decl|url-pos}">{Type.Name|html-esc}</a></h2>
                        {Doc|html-comment}
                        <p><pre>{Decl|html}</pre></p>
                        {.repeated section Consts}
                                <pre>{Decl|html}</pre>
                        {.end}
                        {.repeated section Factories}
-                               <h3 id="{Type.Name|html-esc}.{Name|html-esc}">func <a href="{Decl|url-pos}">{Name|html}</a></h3>
+                               <h3 id="{Type.Name|html-esc}.{Name|html-esc}">func <a href="/{Decl|url-pos}">{Name|html-esc}</a></h3>
                                <p><code>{Decl|html}</code></p>
                                {Doc|html-comment}
                        {.end}
                        {.repeated section Methods}
-                               <h3 id="{Type.Name|html-esc}.{Name|html-esc}">func ({Recv|html}) <a href="{Decl|url-pos}">{Name|html}</a></h3>
+                               <h3 id="{Type.Name|html-esc}.{Name|html-esc}">func ({Recv|html}) <a href="/{Decl|url-pos}">{Name|html-esc}</a></h3>
                                <p><code>{Decl|html}</code></p>
                                {Doc|html-comment}
                        {.end}
        {.repeated section List}
                <tr>
                {Depth|padding}
-               <td align="left" colspan="{Height|html-esc}"><a href="{Path|html-esc}">{Name|html}<a></td>
+               <td align="left" colspan="{Height|html-esc}"><a href="{Path|html-esc}">{Name|html-esc}<a></td>
                <td></td>
-               <td align="left">{Synopsis|html}</td>
+               <td align="left">{Synopsis|html-esc}</td>
                </tr>
        {.end}
        </table>
index 3d417aa27155ac545dfedd7ef7b167bcd3f786fd..febd7e5693d02e67382ab0f497c45a6c1e6f6552 100644 (file)
@@ -14,7 +14,7 @@
        <p>
        <span class="alert" style="font-size:120%">Did you mean: </span>
        {.repeated section Alts}
-               <a href="search?q={@|html-esc}" style="font-size:120%">{@|html}</a>
+               <a href="search?q={@|html-esc}" style="font-size:120%">{@|html-esc}</a>
        {.end}
        </p>
 {.end}
        {.section Decls}
                <h2 id="Global">Package-level declarations</h2>
                {.repeated section @}
-                       <h3 id="Global_{Pak.Path|url-pkg}">package <a href="{Pak.Path|url-pkg}">{Pak.Name|html}</a></h3>
+                       <h3 id="Global_{Pak.Path|url-pkg}">package <a href="/{Pak.Path|url-pkg}">{Pak.Name|html-esc}</a></h3>
                        {.repeated section Files}
                                {.repeated section Groups}
                                        {.repeated section Infos}
-                                               <a href="{File.Path|url-src}?h={Query|html-esc}#L{@|infoLine}">{File.Path|url-src}:{@|infoLine}</a>
+                                               <a href="/{File.Path|url-src}?h={Query|html-esc}#L{@|infoLine}">{File.Path|url-src}:{@|infoLine}</a>
                                                <pre>{@|infoSnippet}</pre>
                                        {.end}
                                {.end}
@@ -36,9 +36,9 @@
        {.section Others}
                <h2 id="Local">Local declarations and uses</h2>
                {.repeated section @}
-                       <h3 id="Local_{Pak.Path|url-pkg}">package <a href="{Pak.Path|url-pkg}">{Pak.Name|html}</a></h3>
+                       <h3 id="Local_{Pak.Path|url-pkg}">package <a href="/{Pak.Path|url-pkg}">{Pak.Name|html-esc}</a></h3>
                        {.repeated section Files}
-                               <a href="{File.Path|url-src}?h={Query|html-esc}">{File.Path|url-src}</a>
+                               <a href="/{File.Path|url-src}?h={Query|html-esc}">{File.Path|url-src}</a>
                                <table class="layout">
                                {.repeated section Groups}
                                        <tr>
@@ -47,7 +47,7 @@
                                        <td align="left" width="4"></td>
                                        <td>
                                        {.repeated section Infos}
-                                               <a href="{File.Path|url-src}?h={Query|html-esc}#L{@|infoLine}">{@|infoLine}</a>
+                                               <a href="/{File.Path|url-src}?h={Query|html-esc}#L{@|infoLine}">{@|infoLine}</a>
                                        {.end}
                                        </td>
                                        </tr>
index 60a5c38641032f80a5db3b887f519882fb11445e..bde1b4868b4ac8d4a71ea79968a0506e135d35a6 100644 (file)
@@ -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)
        }
 }