Skip to content

Commit

Permalink
static/frontend: add titles to links for visual users
Browse files Browse the repository at this point in the history
frontend: add titles to links

add titles to links for visual users
Screenshot of fix: https://screenshot.googleplex.com/8dUyg5GVTn7iXmg

fixes b/283533047

Change-Id: I2e75c7c6b32add6f42de3a84de34f3219cad935a
GitHub-Last-Rev: 4832e52
GitHub-Pull-Request: #101
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/624236
TryBot-Bypass: Jonathan Amsterdam <[email protected]>
Reviewed-by: Nooras Saba‎ <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Joy Serquina (xWF) <[email protected]>
  • Loading branch information
DBowen33 authored and jba committed Dec 5, 2024
1 parent 400c185 commit 2cbe989
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion internal/fetch/fetchdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ var moduleDocTest = &testModule{
docStrings: map[string][]string{
"doc.test/permalink": {
"<h4 id=\"hdr-This_is_a_heading\">This is a heading <a",
"href=\"#hdr-This_is_a_heading\" aria-label=\"Go to This is a heading\">¶</a></h4>",
"href=\"#hdr-This_is_a_heading\" title=\"Go to This is a heading\" aria-label=\"Go to This is a heading\">¶</a></h4>",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/godoc/dochtml/dochtml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestExampleRender(t *testing.T) {
name: "Executable examples (with play buttons)",
htmlID: "example-package-StringsCompare",
want: `<details tabindex="-1" id="example-package-StringsCompare" class="Documentation-exampleDetails js-exampleContainer">
<summary class="Documentation-exampleDetailsHeader">Example (StringsCompare) <a href="#example-package-StringsCompare" aria-label="Go to Example (StringsCompare)">¶</a></summary>
<summary class="Documentation-exampleDetailsHeader">Example (StringsCompare) <a href="#example-package-StringsCompare" title="Go to Example (StringsCompare)" aria-label="Go to Example (StringsCompare)">¶</a></summary>
<div class="Documentation-exampleDetailsBody">
<p>executable example
</p>
Expand Down
2 changes: 1 addition & 1 deletion internal/godoc/dochtml/internal/render/linkify.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var (
// expects a heading
headingTemplate = template.Must(template.New("heading").Parse(`
{{- if .ID.String -}}
<h4 id="{{.ID}}">{{.Title}} <a class="Documentation-idLink" href="#{{.ID}}" aria-label="Go to {{.Title}}">¶</a></h4>
<h4 id="{{.ID}}">{{.Title}} <a class="Documentation-idLink" href="#{{.ID}}" title="Go to {{.Title}}" aria-label="Go to {{.Title}}">¶</a></h4>
{{- else -}}
<h4>{{.Title}}</h4>
{{- end}}`))
Expand Down
4 changes: 2 additions & 2 deletions internal/godoc/dochtml/internal/render/linkify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ More text.`
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-The_Go_Project">The Go Project <a class="Documentation-idLink" href="#hdr-The_Go_Project" aria-label="Go to The Go Project">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-Heading_2">Heading 2 <a class="Documentation-idLink" href="#hdr-Heading_2" aria-label="Go to Heading 2">¶</a></h4><p>More text.
</p><h4 id="hdr-The_Go_Project">The Go Project <a class="Documentation-idLink" href="#hdr-The_Go_Project" title="Go to The Go Project" aria-label="Go to The Go Project">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-Heading_2">Heading 2 <a class="Documentation-idLink" href="#hdr-Heading_2" title="Go to Heading 2" aria-label="Go to Heading 2">¶</a></h4><p>More text.
</p>`)

r := New(context.Background(), nil, pkgTime, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/godoc/dochtml/internal/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var docDataTmpl = template.Must(template.New("").Parse(`
{{end -}}
{{- range .Elements -}}
{{- if .IsHeading -}}
<h4 id="{{.ID}}">{{.Title}} <a class="Documentation-idLink" href="#{{.ID}}" aria-label="Go to {{.Title}}">¶</a></h4>
<h4 id="{{.ID}}">{{.Title}} <a class="Documentation-idLink" href="#{{.ID}}" title="Go to {{.Title}}" aria-label="Go to {{.Title}}">¶</a></h4>
{{- else if .IsPreformat -}}
<pre>{{.Body}}</pre>
{{- else -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Go is an open source project.
</div>
<p>The Go Project1
</p><p>Go is an open source project.
</p><h4 id="hdr-The_Go_Project2">The Go Project2 <a class="Documentation-idLink" href="#hdr-The_Go_Project2" aria-label="Go to The Go Project2">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-The_Go_Project2">The Go Project2 <a class="Documentation-idLink" href="#hdr-The_Go_Project2" title="Go to The Go Project2" aria-label="Go to The Go Project2">¶</a></h4><p>Go is an open source project.
</p>


Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ More doc.
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-The_Go_Project">The Go Project <a class="Documentation-idLink" href="#hdr-The_Go_Project" aria-label="Go to The Go Project">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-Links">Links <a class="Documentation-idLink" href="#hdr-Links" aria-label="Go to Links">¶</a></h4><p>- title1, url1
</p><h4 id="hdr-The_Go_Project">The Go Project <a class="Documentation-idLink" href="#hdr-The_Go_Project" title="Go to The Go Project" aria-label="Go to The Go Project">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-Links">Links <a class="Documentation-idLink" href="#hdr-Links" title="Go to Links" aria-label="Go to Links">¶</a></h4><p>- title1, url1
</p><ul class="Documentation-bulletList">
<li>title2 , url2</li>
</ul><h4 id="hdr-Header">Header <a class="Documentation-idLink" href="#hdr-Header" aria-label="Go to Header">¶</a></h4><p>More doc.
</ul><h4 id="hdr-Header">Header <a class="Documentation-idLink" href="#hdr-Header" title="Go to Header" aria-label="Go to Header">¶</a></h4><p>More doc.
</p>
-- want:links --
<div role="navigation" aria-label="Table of Contents">
Expand All @@ -40,8 +40,8 @@ More doc.
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-The_Go_Project">The Go Project <a class="Documentation-idLink" href="#hdr-The_Go_Project" aria-label="Go to The Go Project">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-Header">Header <a class="Documentation-idLink" href="#hdr-Header" aria-label="Go to Header">¶</a></h4><p>More doc.
</p><h4 id="hdr-The_Go_Project">The Go Project <a class="Documentation-idLink" href="#hdr-The_Go_Project" title="Go to The Go Project" aria-label="Go to The Go Project">¶</a></h4><p>Go is an open source project.
</p><h4 id="hdr-Header">Header <a class="Documentation-idLink" href="#hdr-Header" title="Go to Header" aria-label="Go to Header">¶</a></h4><p>More doc.
</p>
-- links --
title1 url1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Run() {}
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-Info-Run">Info <a class="Documentation-idLink" href="#hdr-Info-Run" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-Run-1">Info <a class="Documentation-idLink" href="#hdr-Info-Run-1" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p><h4 id="hdr-Info-Run">Info <a class="Documentation-idLink" href="#hdr-Info-Run" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-Run-1">Info <a class="Documentation-idLink" href="#hdr-Info-Run-1" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p>

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (T) M() {}
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-Info-T_M">Info <a class="Documentation-idLink" href="#hdr-Info-T_M" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-T_M-1">Info <a class="Documentation-idLink" href="#hdr-Info-T_M-1" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p><h4 id="hdr-Info-T_M">Info <a class="Documentation-idLink" href="#hdr-Info-T_M" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-T_M-1">Info <a class="Documentation-idLink" href="#hdr-Info-T_M-1" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p>

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This is some other information.
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-Info">Info <a class="Documentation-idLink" href="#hdr-Info" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-1">Info <a class="Documentation-idLink" href="#hdr-Info-1" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p><h4 id="hdr-Info">Info <a class="Documentation-idLink" href="#hdr-Info" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-1">Info <a class="Documentation-idLink" href="#hdr-Info-1" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p>

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var Global int
</ul>
</div>
<p>Documentation.
</p><h4 id="hdr-Info-Global">Info <a class="Documentation-idLink" href="#hdr-Info-Global" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-Global-1">Info <a class="Documentation-idLink" href="#hdr-Info-Global-1" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p><h4 id="hdr-Info-Global">Info <a class="Documentation-idLink" href="#hdr-Info-Global" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some information.
</p><h4 id="hdr-Info-Global-1">Info <a class="Documentation-idLink" href="#hdr-Info-Global-1" title="Go to Info" aria-label="Go to Info">¶</a></h4><p>This is some other information.
</p>

22 changes: 11 additions & 11 deletions internal/godoc/dochtml/testdata/comments.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="Documentation-content js-docContent"> <section class="Documentation-overview">
<h3 tabindex="-1" id="pkg-overview" class="Documentation-overviewHeader">Overview <a href="#pkg-overview" aria-label="Go to Overview">¶</a></h3>
<h3 tabindex="-1" id="pkg-overview" class="Documentation-overviewHeader">Overview <a href="#pkg-overview" title="Go to Overview" aria-label="Go to Overview">¶</a></h3>
<p>Package comments exercises the Go 1.19 doc comment features.
This refers to the standard library <a href="/encoding/json">encoding/json</a> package.
</p>
</section><section class="Documentation-index">
<h3 id="pkg-index" class="Documentation-indexHeader">Index <a href="#pkg-index" aria-label="Go to Index">¶</a></h3>
<h3 id="pkg-index" class="Documentation-indexHeader">Index <a href="#pkg-index" title="Go to Index" aria-label="Go to Index">¶</a></h3>
<ul class="Documentation-indexList">
<li class="Documentation-indexFunction">
<a href="#F">func F()</a></li>
Expand All @@ -17,14 +17,14 @@ This refers to the standard library <a href="/encoding/json">encoding/json</a> p
<a href="#T.M">func (T) M() safe.HTML</a></li>
</ul></li>
</ul>
</section><h3 tabindex="-1" id="pkg-constants" class="Documentation-constantsHeader">Constants <a href="#pkg-constants" aria-label="Go to Constants">¶</a></h3>
</section><h3 tabindex="-1" id="pkg-constants" class="Documentation-constantsHeader">Constants <a href="#pkg-constants" title="Go to Constants" aria-label="Go to Constants">¶</a></h3>
<section class="Documentation-constants"><p class="Documentation-empty">This section is empty.</p></section>
<h3 tabindex="-1" id="pkg-variables" class="Documentation-variablesHeader">Variables <a href="#pkg-variables" aria-label="Go to Variables">¶</a></h3>
<h3 tabindex="-1" id="pkg-variables" class="Documentation-variablesHeader">Variables <a href="#pkg-variables" title="Go to Variables" aria-label="Go to Variables">¶</a></h3>
<section class="Documentation-variables"><p class="Documentation-empty">This section is empty.</p></section>
<h3 tabindex="-1" id="pkg-functions" class="Documentation-functionsHeader">Functions <a href="#pkg-functions" aria-label="Go to Functions">¶</a></h3>
<h3 tabindex="-1" id="pkg-functions" class="Documentation-functionsHeader">Functions <a href="#pkg-functions" title="Go to Functions" aria-label="Go to Functions">¶</a></h3>
<section class="Documentation-functions"><div class="Documentation-function">
<h4 tabindex="-1" id="F" data-kind="function" class="Documentation-functionHeader">
<span>func <a class="Documentation-source" href="src">F</a> <a class="Documentation-idLink" href="#F" aria-label="Go to F">¶</a></span>
<span>func <a class="Documentation-source" href="src">F</a> <a class="Documentation-idLink" href="#F" title="Go to F" aria-label="Go to F">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
Expand All @@ -42,12 +42,12 @@ It also has three bullet points:
<li>one</li>
<li>two</li>
<li>three</li>
</ul><h4 id="hdr-Example-F">Example <a class="Documentation-idLink" href="#hdr-Example-F" aria-label="Go to Example">¶</a></h4><p>Here is an example:
</ul><h4 id="hdr-Example-F">Example <a class="Documentation-idLink" href="#hdr-Example-F" title="Go to Example" aria-label="Go to Example">¶</a></h4><p>Here is an example:
</p><pre>F()
</pre>
</div><div class="Documentation-function">
<h4 tabindex="-1" id="G" data-kind="function" class="Documentation-functionHeader">
<span>func <a class="Documentation-source" href="src">G</a> <a class="Documentation-idLink" href="#G" aria-label="Go to G">¶</a></span>
<span>func <a class="Documentation-source" href="src">G</a> <a class="Documentation-idLink" href="#G" title="Go to G" aria-label="Go to G">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
Expand All @@ -57,10 +57,10 @@ It also has three bullet points:
<p>G implements something according to <a href="https://pkg.go.dev">this link</a>.
</p>
</div></section>
<h3 tabindex="-1" id="pkg-types" class="Documentation-typesHeader">Types <a href="#pkg-types" aria-label="Go to Types">¶</a></h3>
<h3 tabindex="-1" id="pkg-types" class="Documentation-typesHeader">Types <a href="#pkg-types" title="Go to Types" aria-label="Go to Types">¶</a></h3>
<section class="Documentation-types"><div class="Documentation-type">
<h4 tabindex="-1" id="T" data-kind="type" class="Documentation-typeHeader">
<span>type <a class="Documentation-source" href="src">T</a> <a class="Documentation-idLink" href="#T" aria-label="Go to T">¶</a></span>
<span>type <a class="Documentation-source" href="src">T</a> <a class="Documentation-idLink" href="#T" title="Go to T" aria-label="Go to T">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
Expand All @@ -76,7 +76,7 @@ module: <a href="/example.com/[email protected]/pkg">example.com/module/pkg</a>.
</p>
<div class="Documentation-typeMethod">
<h4 tabindex="-1" id="T.M" data-kind="method" class="Documentation-typeMethodHeader">
<span>func (T) <a class="Documentation-source" href="src">M</a> <a class="Documentation-idLink" href="#T.M" aria-label="Go to T.M">¶</a></span>
<span>func (T) <a class="Documentation-source" href="src">M</a> <a class="Documentation-idLink" href="#T.M" title="Go to T.M" aria-label="Go to T.M">¶</a></span>
<span class="Documentation-sinceVersion">
</span>
</h4>
Expand Down
Loading

0 comments on commit 2cbe989

Please sign in to comment.