Skip to content

Commit 2c200ee

Browse files
nwidgeradg
authored andcommitted
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 (&#xb6; HTML entity). Fixes: golang/go#13748 Change-Id: I645269f6c229f76b2882899e1a7483577877ac30 Reviewed-on: https://go-review.googlesource.com/20246 Reviewed-by: Andrew Gerrand <adg@golang.org>
1 parent 0b2f4dc commit 2c200ee

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

godoc/static/package.html

+12-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ <h2 id="pkg-variables">Variables</h2>
165165
{{range .Funcs}}
166166
{{/* Name is a string - no need for FSet */}}
167167
{{$name_html := html .Name}}
168-
<h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h2>
168+
<h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
169+
<a class="permalink" href="#{{$name_html}}">&#xb6;</a>
170+
</h2>
169171
<pre>{{node_html $ .Decl true}}</pre>
170172
{{comment_html .Doc}}
171173
{{example_html $ .Name}}
@@ -175,7 +177,9 @@ <h2 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a
175177
{{range .Types}}
176178
{{$tname := .Name}}
177179
{{$tname_html := html .Name}}
178-
<h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a></h2>
180+
<h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}</a>
181+
<a class="permalink" href="#{{$tname_html}}">&#xb6;</a>
182+
</h2>
179183
<pre>{{node_html $ .Decl true}}</pre>
180184
{{comment_html .Doc}}
181185

@@ -195,7 +199,9 @@ <h2 id="{{$tname_html}}">type <a href="{{posLink_url $ .Decl}}">{{$tname_html}}<
195199

196200
{{range .Funcs}}
197201
{{$name_html := html .Name}}
198-
<h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3>
202+
<h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
203+
<a class="permalink" href="#{{$tname_html}}">&#xb6;</a>
204+
</h3>
199205
<pre>{{node_html $ .Decl true}}</pre>
200206
{{comment_html .Doc}}
201207
{{example_html $ .Name}}
@@ -204,7 +210,9 @@ <h3 id="{{$name_html}}">func <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a
204210

205211
{{range .Methods}}
206212
{{$name_html := html .Name}}
207-
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a></h3>
213+
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url $ .Decl}}">{{$name_html}}</a>
214+
<a class="permalink" href="#{{$tname_html}}.{{$name_html}}">&#xb6;</a>
215+
</h3>
208216
<pre>{{node_html $ .Decl true}}</pre>
209217
{{comment_html .Doc}}
210218
{{$name := printf "%s_%s" $tname .Name}}

godoc/static/static.go

+20-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

godoc/static/style.css

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ a:hover,
4242
.exampleHeading .text:hover {
4343
text-decoration: underline;
4444
}
45+
46+
.permalink {
47+
display: none;
48+
}
49+
h2:hover .permalink, h3:hover .permalink {
50+
display: inline;
51+
}
52+
4553
p, li {
4654
max-width: 800px;
4755
word-wrap: break-word;

0 commit comments

Comments
 (0)