cmd/godoc: Add anchor links to functions, types and methods

Added anchor link beside each function, type and method definition in
godoc's generated HTML.  Anchor links are only shown when the mouse is
hovering over the definition.  The link body is the Unicode PILCROW SIGN
character (¶ HTML entity).

Fixes: golang/go#13748

Change-Id: I645269f6c229f76b2882899e1a7483577877ac30
Reviewed-on: https://go-review.googlesource.com/20246
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
nwidger 2016-03-06 09:31:52 -05:00 committed by Andrew Gerrand
parent 0b2f4dcf4d
commit 2c200eec40
3 changed files with 40 additions and 8 deletions

View File

@ -165,7 +165,9 @@
{{range .Funcs}} {{range .Funcs}}
{{/* Name is a string - no need for FSet */}} {{/* Name is a string - no need for FSet */}}
{{$name_html := html .Name}} {{$name_html := html .Name}}
<h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h2> <h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
<a class="permalink" href="#{{$name_html}}">&#xb6;</a>
</h2>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
{{example_html $ .Name}} {{example_html $ .Name}}
@ -175,7 +177,9 @@
{{range .Types}} {{range .Types}}
{{$tname := .Name}} {{$tname := .Name}}
{{$tname_html := html .Name}} {{$tname_html := html .Name}}
<h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a></h2> <h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a>
<a class="permalink" href="#{{$tname_html}}">&#xb6;</a>
</h2>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
@ -195,7 +199,9 @@
{{range .Funcs}} {{range .Funcs}}
{{$name_html := html .Name}} {{$name_html := html .Name}}
<h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3> <h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
<a class="permalink" href="#{{$tname_html}}">&#xb6;</a>
</h3>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
{{example_html $ .Name}} {{example_html $ .Name}}
@ -204,7 +210,9 @@
{{range .Methods}} {{range .Methods}}
{{$name_html := html .Name}} {{$name_html := html .Name}}
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3> <h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
<a class="permalink" href="#{{$tname_html}}.{{$name_html}}">&#xb6;</a>
</h3>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
{{$name := printf "%s_%s" $tname .Name}} {{$name := printf "%s_%s" $tname .Name}}

View File

@ -1748,7 +1748,9 @@ function cgAddChild(tree, ul, cgn) {
{{range .Funcs}} {{range .Funcs}}
{{/* Name is a string - no need for FSet */}} {{/* Name is a string - no need for FSet */}}
{{$name_html := html .Name}} {{$name_html := html .Name}}
<h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h2> <h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
<a class="permalink" href="#{{$name_html}}">&#xb6;</a>
</h2>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
{{example_html $ .Name}} {{example_html $ .Name}}
@ -1758,7 +1760,9 @@ function cgAddChild(tree, ul, cgn) {
{{range .Types}} {{range .Types}}
{{$tname := .Name}} {{$tname := .Name}}
{{$tname_html := html .Name}} {{$tname_html := html .Name}}
<h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a></h2> <h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a>
<a class="permalink" href="#{{$tname_html}}">&#xb6;</a>
</h2>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
@ -1778,7 +1782,9 @@ function cgAddChild(tree, ul, cgn) {
{{range .Funcs}} {{range .Funcs}}
{{$name_html := html .Name}} {{$name_html := html .Name}}
<h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3> <h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
<a class="permalink" href="#{{$tname_html}}">&#xb6;</a>
</h3>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
{{example_html $ .Name}} {{example_html $ .Name}}
@ -1787,7 +1793,9 @@ function cgAddChild(tree, ul, cgn) {
{{range .Methods}} {{range .Methods}}
{{$name_html := html .Name}} {{$name_html := html .Name}}
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3> <h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
<a class="permalink" href="#{{$tname_html}}.{{$name_html}}">&#xb6;</a>
</h3>
<pre>{{node_html $ .Decl true}}</pre> <pre>{{node_html $ .Decl true}}</pre>
{{comment_html .Doc}} {{comment_html .Doc}}
{{$name := printf "%s_%s" $tname .Name}} {{$name := printf "%s_%s" $tname .Name}}
@ -2826,6 +2834,14 @@ a:hover,
.exampleHeading .text:hover { .exampleHeading .text:hover {
text-decoration: underline; text-decoration: underline;
} }
.permalink {
display: none;
}
h2:hover .permalink, h3:hover .permalink {
display: inline;
}
p, li { p, li {
max-width: 800px; max-width: 800px;
word-wrap: break-word; word-wrap: break-word;

View File

@ -42,6 +42,14 @@ a:hover,
.exampleHeading .text:hover { .exampleHeading .text:hover {
text-decoration: underline; text-decoration: underline;
} }
.permalink {
display: none;
}
h2:hover .permalink, h3:hover .permalink {
display: inline;
}
p, li { p, li {
max-width: 800px; max-width: 800px;
word-wrap: break-word; word-wrap: break-word;