{{range .}}
{{/* Name is a string - no need for FSet */}}
{{$name := html .Name}}
- <h2 id="{{$name}}">func <a href="/{{posLink .Decl $.FSet}}">{{$name}}</a></h2>
+ <h2 id="{{$name}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name}}</a></h2>
<p><code>{{node_html .Decl $.FSet}}</code></p>
{{comment_html .Doc}}
{{end}}
{{with .Types}}
{{range .}}
{{$tname := node_html .Type.Name $.FSet}}
- <h2 id="{{$tname}}">type <a href="/{{posLink .Decl $.FSet}}">{{$tname}}</a></h2>
+ <h2 id="{{$tname}}">type <a href="/{{posLink_url .Decl $.FSet}}">{{$tname}}</a></h2>
{{comment_html .Doc}}
<p><pre>{{node_html .Decl $.FSet}}</pre></p>
{{range .Consts}}
{{end}}
{{range .Factories}}
{{$name := html .Name}}
- <h3 id="{{$tname}}.{{$name}}">func <a href="/{{posLink .Decl $.FSet}}">{{$name}}</a></h3>
+ <h3 id="{{$tname}}.{{$name}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name}}</a></h3>
<p><code>{{node_html .Decl $.FSet}}</code></p>
{{comment_html .Doc}}
{{end}}
{{range .Methods}}
{{$name := html .Name}}
- <h3 id="{{$tname}}.{{$name}}">func ({{node_html .Recv $.FSet}}) <a href="/{{posLink .Decl $.FSet}}">{{$name}}</a></h3>
+ <h3 id="{{$tname}}.{{$name}}">func ({{node_html .Recv $.FSet}}) <a href="/{{posLink_url .Decl $.FSet}}">{{$name}}</a></h3>
<p><code>{{node_html .Decl $.FSet}}</code></p>
{{comment_html .Doc}}
{{end}}
return pkgHandler.pattern[1:] + relpath // remove trailing '/' for relative URL
}
-func posLinkFunc(node ast.Node, fset *token.FileSet) string {
+func posLink_urlFunc(node ast.Node, fset *token.FileSet) string {
var relpath string
var line int
var low, high int // selection
}
var buf bytes.Buffer
- buf.WriteString(relpath)
+ buf.WriteString(http.URLEscape(relpath))
// selection ranges are of form "s=low:high"
if low < high {
- fmt.Fprintf(&buf, "?s=%d:%d", low, high)
+ fmt.Fprintf(&buf, "?s=%d:%d", low, high) // no need for URL escaping
// if we have a selection, position the page
// such that the selection is a bit below the top
line -= 10
// line id's in html-printed source are of the
// form "L%d" where %d stands for the line number
if line > 0 {
- fmt.Fprintf(&buf, "#L%d", line)
+ fmt.Fprintf(&buf, "#L%d", line) // no need for URL escaping
}
return buf.String()
}
// fmap describes the template functions installed with all godoc templates.
-// Convention: template function names ending in "_html" produce an HTML-
-// escaped string; all other function results may require HTML
-// or URL escaping in the template.
+// Convention: template function names ending in "_html" or "_url" produce
+// HTML- or URL-escaped strings; all other function results may
+// require explicit escaping in the template.
var fmap = template.FuncMap{
// various helpers
"filename": filenameFunc,
"comment_html": comment_htmlFunc,
// support for URL attributes
- "pkgLink": pkgLinkFunc,
- "srcLink": relativeURL,
- "posLink": posLinkFunc,
+ "pkgLink": pkgLinkFunc,
+ "srcLink": relativeURL,
+ "posLink_url": posLink_urlFunc,
}
func readTemplate(name string) *template.Template {