From 2c200eec40d70d74e01852aad22cf6637e8f8f3d Mon Sep 17 00:00:00 2001 From: nwidger Date: Sun, 6 Mar 2016 09:31:52 -0500 Subject: [PATCH] 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 --- godoc/static/package.html | 16 ++++++++++++---- godoc/static/static.go | 24 ++++++++++++++++++++---- godoc/static/style.css | 8 ++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/godoc/static/package.html b/godoc/static/package.html index 7f38c51a58..549825bb33 100644 --- a/godoc/static/package.html +++ b/godoc/static/package.html @@ -165,7 +165,9 @@ {{range .Funcs}} {{/* Name is a string - no need for FSet */}} {{$name_html := html .Name}} -

func {{$name_html}}

+

func {{$name_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} {{example_html $ .Name}} @@ -175,7 +177,9 @@ {{range .Types}} {{$tname := .Name}} {{$tname_html := html .Name}} -

type {{$tname_html}}

+

type {{$tname_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} @@ -195,7 +199,9 @@ {{range .Funcs}} {{$name_html := html .Name}} -

func {{$name_html}}

+

func {{$name_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} {{example_html $ .Name}} @@ -204,7 +210,9 @@ {{range .Methods}} {{$name_html := html .Name}} -

func ({{html .Recv}}) {{$name_html}}

+

func ({{html .Recv}}) {{$name_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} {{$name := printf "%s_%s" $tname .Name}} diff --git a/godoc/static/static.go b/godoc/static/static.go index 6aadc86a84..1bb0bb897d 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -1748,7 +1748,9 @@ function cgAddChild(tree, ul, cgn) { {{range .Funcs}} {{/* Name is a string - no need for FSet */}} {{$name_html := html .Name}} -

func {{$name_html}}

+

func {{$name_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} {{example_html $ .Name}} @@ -1758,7 +1760,9 @@ function cgAddChild(tree, ul, cgn) { {{range .Types}} {{$tname := .Name}} {{$tname_html := html .Name}} -

type {{$tname_html}}

+

type {{$tname_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} @@ -1778,7 +1782,9 @@ function cgAddChild(tree, ul, cgn) { {{range .Funcs}} {{$name_html := html .Name}} -

func {{$name_html}}

+

func {{$name_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} {{example_html $ .Name}} @@ -1787,7 +1793,9 @@ function cgAddChild(tree, ul, cgn) { {{range .Methods}} {{$name_html := html .Name}} -

func ({{html .Recv}}) {{$name_html}}

+

func ({{html .Recv}}) {{$name_html}} + +

{{node_html $ .Decl true}}
{{comment_html .Doc}} {{$name := printf "%s_%s" $tname .Name}} @@ -2826,6 +2834,14 @@ a:hover, .exampleHeading .text:hover { text-decoration: underline; } + +.permalink { + display: none; +} +h2:hover .permalink, h3:hover .permalink { + display: inline; +} + p, li { max-width: 800px; word-wrap: break-word; diff --git a/godoc/static/style.css b/godoc/static/style.css index 8ea08525f3..fd26bd85fc 100644 --- a/godoc/static/style.css +++ b/godoc/static/style.css @@ -42,6 +42,14 @@ a:hover, .exampleHeading .text:hover { text-decoration: underline; } + +.permalink { + display: none; +} +h2:hover .permalink, h3:hover .permalink { + display: inline; +} + p, li { max-width: 800px; word-wrap: break-word;