1
0
mirror of https://github.com/golang/go synced 2024-11-24 17:20:12 -07:00

Distinguish between html generation and html quoting in godoc formatters.

Replacement for CL 184084; originally by Roger Peppe (rogpeppe@gmail.com).

R=rsc
CC=golang-dev, rog
https://golang.org/cl/189059
This commit is contained in:
Robert Griesemer 2010-01-13 15:18:56 -08:00
parent 6ae763a727
commit 27be2915f3
5 changed files with 22 additions and 13 deletions

View File

@ -18,7 +18,7 @@
</tr> </tr>
{.repeated section @} {.repeated section @}
<tr> <tr>
<td align="left"><a href="{Name|html}{@|dir/}">{Name|html}{@|dir/}</a></td> <td align="left"><a href="{Name|html-esc}{@|dir/}">{Name|html}{@|dir/}</a></td>
<td></td> <td></td>
<td align="right">{Size|html}</td> <td align="right">{Size|html}</td>
<td></td> <td></td>

View File

@ -106,7 +106,7 @@
<li class="blank">&nbsp;</li> <li class="blank">&nbsp;</li>
<li class="navhead">Go code search</li> <li class="navhead">Go code search</li>
<form method="GET" action="/search" class="search"> <form method="GET" action="/search" class="search">
<input type="search" name="q" value="{Query|html}" size="25" style="width:80%; max-width:200px" /> <input type="search" name="q" value="{Query|html-esc}" size="25" style="width:80%; max-width:200px" />
<input type="submit" value="Go" /> <input type="submit" value="Go" />
</form> </form>

View File

@ -16,7 +16,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="/{FilePath|html}/{@|html}">{@|html}</a> <a href="/{FilePath|html-esc}/{@|html-esc}">{@|html}</a>
{.end} {.end}
</span> </span>
</p> </p>
@ -38,14 +38,14 @@
{.end} {.end}
{.section Funcs} {.section Funcs}
{.repeated section @} {.repeated section @}
<h2 id="{Name|html}">func <a href="{Decl|link}">{Name|html}</a></h2> <h2 id="{Name|html-esc}">func <a href="{Decl|link}">{Name|html}</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}">type <a href="{Decl|link}">{Type.Name|html}</a></h2> <h2 id="{Type.Name|html-esc}">type <a href="{Decl|link}">{Type.Name|html}</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}
@ -57,12 +57,12 @@
<pre>{Decl|html}</pre> <pre>{Decl|html}</pre>
{.end} {.end}
{.repeated section Factories} {.repeated section Factories}
<h3 id="{Type.Name|html}.{Name|html}">func <a href="{Decl|link}">{Name|html}</a></h3> <h3 id="{Type.Name|html-esc}.{Name|html-esc}">func <a href="{Decl|link}">{Name|html}</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}.{Name|html}">func ({Recv|html}) <a href="{Decl|link}">{Name|html}</a></h3> <h3 id="{Type.Name|html-esc}.{Name|html-esc}">func ({Recv|html}) <a href="{Decl|link}">{Name|html}</a></h3>
<p><code>{Decl|html}</code></p> <p><code>{Decl|html}</code></p>
{Doc|html-comment} {Doc|html-comment}
{.end} {.end}
@ -80,7 +80,7 @@
<p> <p>
<table class="layout"> <table class="layout">
<tr> <tr>
<th align="left" colspan="{MaxHeight|html}">Name</th> <th align="left" colspan="{MaxHeight|html-esc}">Name</th>
<td width="25">&nbsp;</td> <td width="25">&nbsp;</td>
<th align="left">Synopsis</th> <th align="left">Synopsis</th>
</tr> </tr>
@ -90,7 +90,7 @@
{.repeated section List} {.repeated section List}
<tr> <tr>
{Depth|padding} {Depth|padding}
<td align="left" colspan="{Height|html}"><a href="{Path|html}">{Name|html}<a></td> <td align="left" colspan="{Height|html-esc}"><a href="{Path|html-esc}">{Name|html}<a></td>
<td></td> <td></td>
<td align="left">{Synopsis|html}</td> <td align="left">{Synopsis|html}</td>
</tr> </tr>

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}" style="font-size:120%">{@|html}</a> <a href="search?q={@|html-esc}" style="font-size:120%">{@|html}</a>
{.end} {.end}
</p> </p>
{.end} {.end}
@ -26,7 +26,7 @@
{.repeated section Files} {.repeated section Files}
{.repeated section Groups} {.repeated section Groups}
{.repeated section Infos} {.repeated section Infos}
<a href="{File.Path|html}?h={Query|html}#L{@|infoLine}">{File.Path|html}:{@|infoLine}</a> <a href="{File.Path|html-esc}?h={Query|html-esc}#L{@|infoLine}">{File.Path|html}:{@|infoLine}</a>
<pre>{@|infoSnippet}</pre> <pre>{@|infoSnippet}</pre>
{.end} {.end}
{.end} {.end}
@ -38,7 +38,7 @@
{.repeated section @} {.repeated section @}
<h3 id="Local_{Pak.Path|path}">package <a href="{Pak.Path|path}">{Pak.Name|html}</a></h3> <h3 id="Local_{Pak.Path|path}">package <a href="{Pak.Path|path}">{Pak.Name|html}</a></h3>
{.repeated section Files} {.repeated section Files}
<a href="{File.Path|html}?h={Query|html}">{File.Path|html}</a> <a href="{File.Path|html-esc}?h={Query|html-esc}">{File.Path|html}</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|html}?h={Query|html}#L{@|infoLine}">{@|infoLine}</a> <a href="{File.Path|html-esc}?h={Query|html-esc}#L{@|infoLine}">{@|infoLine}</a>
{.end} {.end}
</td> </td>
</tr> </tr>

View File

@ -587,6 +587,14 @@ func htmlFmt(w io.Writer, x interface{}, format string) {
} }
// Template formatter for "html-esc" format.
func htmlEscFmt(w io.Writer, x interface{}, format string) {
var buf bytes.Buffer
writeAny(&buf, x, false)
template.HTMLEscape(w, buf.Bytes())
}
// Template formatter for "html-comment" format. // Template formatter for "html-comment" format.
func htmlCommentFmt(w io.Writer, x interface{}, format string) { func htmlCommentFmt(w io.Writer, x interface{}, format string) {
var buf bytes.Buffer var buf bytes.Buffer
@ -705,6 +713,7 @@ func dirslashFmt(w io.Writer, x interface{}, format string) {
var fmap = template.FormatterMap{ var fmap = template.FormatterMap{
"": textFmt, "": textFmt,
"html": htmlFmt, "html": htmlFmt,
"html-esc": htmlEscFmt,
"html-comment": htmlCommentFmt, "html-comment": htmlCommentFmt,
"path": pathFmt, "path": pathFmt,
"link": linkFmt, "link": linkFmt,