1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:14:40 -07:00

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
This commit is contained in:
Robert Griesemer 2010-03-24 16:28:59 -07:00
parent bf9b8f2c17
commit acfd6d5f05
5 changed files with 24 additions and 23 deletions

View File

@ -18,9 +18,9 @@
</tr> </tr>
{.repeated section @} {.repeated section @}
<tr> <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></td>
<td align="right">{Size|html}</td> <td align="right">{Size|html-esc}</td>
<td></td> <td></td>
<td align="left">{Mtime_ns|time}</td> <td align="left">{Mtime_ns|time}</td>
</tr> </tr>

View File

@ -4,7 +4,7 @@
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <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"> <link rel="stylesheet" type="text/css" href="/doc/style.css">
<script type="text/javascript" src="/doc/godocs.js"></script> <script type="text/javascript" src="/doc/godocs.js"></script>
@ -121,7 +121,7 @@
<li class="blank">&nbsp;</li> <li class="blank">&nbsp;</li>
<li class="navhead">Last update</li> <li class="navhead">Last update</li>
<li>{Timestamp|time}</li> <li>{Timestamp|time}</li>
<li>Build version {Version|html}</li> <li>Build version {Version|html-esc}</li>
</ul> </ul>
</div> </div>
@ -133,7 +133,7 @@
</div> </div>
{.end} {.end}
<h1 id="generatedHeader">{Title|html}</h1> <h1 id="generatedHeader">{Title|html-esc}</h1>
<!-- The Table of Contents is automatically inserted in this <div>. <!-- The Table of Contents is automatically inserted in this <div>.
Do not delete this <div>. --> Do not delete this <div>. -->

View File

@ -12,7 +12,7 @@
{.section PDoc} {.section PDoc}
<!-- PackageName is printed as title by the top-level template --> <!-- PackageName is printed as title by the top-level template -->
{.section IsPkg} {.section IsPkg}
<p><code>import "{ImportPath|html}"</code></p> <p><code>import "{ImportPath|html-esc}"</code></p>
{.end} {.end}
{Doc|html-comment} {Doc|html-comment}
{.section IsPkg} {.section IsPkg}
@ -21,7 +21,7 @@
<h4>Package files</h4> <h4>Package files</h4>
<span style="font-size:90%"> <span style="font-size:90%">
{.repeated section @} {.repeated section @}
<a href="{@|url-src}">{@|localname}</a> <a href="/{@|url-src}">{@|localname}</a>
{.end} {.end}
</span> </span>
</p> </p>
@ -43,14 +43,14 @@
{.end} {.end}
{.section Funcs} {.section Funcs}
{.repeated section @} {.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> <p><code>{Decl|html}</code></p>
{Doc|html-comment} {Doc|html-comment}
{.end} {.end}
{.end} {.end}
{.section Types} {.section Types}
{.repeated section @} {.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} {Doc|html-comment}
<p><pre>{Decl|html}</pre></p> <p><pre>{Decl|html}</pre></p>
{.repeated section Consts} {.repeated section Consts}
@ -62,12 +62,12 @@
<pre>{Decl|html}</pre> <pre>{Decl|html}</pre>
{.end} {.end}
{.repeated section Factories} {.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> <p><code>{Decl|html}</code></p>
{Doc|html-comment} {Doc|html-comment}
{.end} {.end}
{.repeated section Methods} {.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> <p><code>{Decl|html}</code></p>
{Doc|html-comment} {Doc|html-comment}
{.end} {.end}
@ -103,9 +103,9 @@
{.repeated section List} {.repeated section List}
<tr> <tr>
{Depth|padding} {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></td>
<td align="left">{Synopsis|html}</td> <td align="left">{Synopsis|html-esc}</td>
</tr> </tr>
{.end} {.end}
</table> </table>

View File

@ -14,7 +14,7 @@
<p> <p>
<span class="alert" style="font-size:120%">Did you mean: </span> <span class="alert" style="font-size:120%">Did you mean: </span>
{.repeated section Alts} {.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} {.end}
</p> </p>
{.end} {.end}
@ -22,11 +22,11 @@
{.section Decls} {.section Decls}
<h2 id="Global">Package-level declarations</h2> <h2 id="Global">Package-level declarations</h2>
{.repeated section @} {.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 Files}
{.repeated section Groups} {.repeated section Groups}
{.repeated section Infos} {.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> <pre>{@|infoSnippet}</pre>
{.end} {.end}
{.end} {.end}
@ -36,9 +36,9 @@
{.section Others} {.section Others}
<h2 id="Local">Local declarations and uses</h2> <h2 id="Local">Local declarations and uses</h2>
{.repeated section @} {.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} {.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"> <table class="layout">
{.repeated section Groups} {.repeated section Groups}
<tr> <tr>
@ -47,7 +47,7 @@
<td align="left" width="4"></td> <td align="left" width="4"></td>
<td> <td>
{.repeated section Infos} {.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} {.end}
</td> </td>
</tr> </tr>

View File

@ -692,7 +692,8 @@ func urlFmt(w io.Writer, x interface{}, format string) {
// map path // map path
relpath := relativePath(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 { switch format {
default: default:
// we should never reach here, but be resilient // 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/") { if strings.HasPrefix(relpath, "src/pkg/") {
relpath = relpath[len("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": case "url-src":
template.HTMLEscape(w, []byte("/"+relpath)) template.HTMLEscape(w, []byte(relpath))
case "url-pos": case "url-pos":
// line id's in html-printed source are of the // line id's in html-printed source are of the
// form "L%d" where %d stands for the line number // 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) fmt.Fprintf(w, "#L%d", line)
} }
} }