Skip to content

Commit 04c3ca7

Browse files
authored
Move action links out from heading tags (#1993)
Avoids action link text being read out as part of "navigated to..." announcements. Closes #1987.
1 parent 626e3bc commit 04c3ca7

File tree

6 files changed

+77
-53
lines changed

6 files changed

+77
-53
lines changed

assets/css/content/functions.css

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616
}
1717

1818
.content-inner .detail-header {
19-
margin: 2 0 1em;
20-
padding: 0.5em 1em;
19+
margin: 1em 0;
20+
padding: 0.5em 0.85em 0.5em 1em;
2121
background-color: var(--textDetailBackground);
2222
border-left: 3px solid var(--textDetailAccent);
2323
font-size: 1em;
2424
font-family: var(--monoFontFamily);
2525
position: relative;
2626
}
2727

28-
.content-inner .detail-header .note {
29-
float: right;
30-
}
31-
3228
.content-inner .detail-header .signature {
33-
display: inline-block;
3429
font-family: var(--monoFontFamily);
3530
font-size: 1rem;
3631
font-weight: 700;
@@ -62,6 +57,10 @@
6257
}
6358
}
6459

60+
.content-inner .detail-header .icon-action {
61+
margin-top: 3px;
62+
}
63+
6564
.content-inner .specs pre {
6665
font-family: var(--monoFontFamily);
6766
font-size: 0.9em;

assets/css/content/general.css

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@
77
color: var(--textBody);
88
}
99

10+
.content-inner .heading-with-actions {
11+
display: flex;
12+
flex-wrap: wrap;
13+
justify-content: flex-end;
14+
align-items: start;
15+
gap: 6px;
16+
}
17+
.content-inner .heading-with-actions > *:not(h1) {
18+
flex-shrink: 0;
19+
}
20+
.content-inner .heading-with-actions h1 {
21+
flex-grow: 1;
22+
justify-self: flex-start;
23+
max-width: 100%;
24+
margin: 0;
25+
overflow-wrap: break-word;
26+
}
27+
.content-inner .heading-with-actions .icon-action {
28+
width: 20px;
29+
height: 20px;
30+
display: flex;
31+
justify-content: center;
32+
align-items: center;
33+
font-weight: normal;
34+
}
35+
.content-inner .heading-with-actions.top-heading .icon-action {
36+
padding-top: 1.5rem;
37+
font-size: 1.2rem;
38+
}
39+
40+
.content-inner .top-heading {
41+
padding-top: 1rem;
42+
}
43+
1044
.content-inner :is(h1, h2, h3, h4, h5, h6) {
1145
font-family: var(--sansFontFamily);
1246
font-weight: 700;
@@ -20,10 +54,6 @@
2054
margin: 0.5em 0;
2155
}
2256

23-
.content-inner h1.signature {
24-
margin: 0;
25-
}
26-
2757
.content-inner h1.section-heading {
2858
margin: 1.5em 0 0.5em;
2959
}
@@ -32,11 +62,6 @@
3262
font-weight: 300;
3363
}
3464

35-
.content-inner h1 .icon-action {
36-
font-size: 1.2rem;
37-
font-weight: normal;
38-
}
39-
4065
.content-inner h2 {
4166
font-size: 1.6em;
4267
padding-top: 1em;
@@ -65,17 +90,13 @@
6590
}
6691

6792
.content-inner .icon-action {
68-
float: right;
6993
color: var(--iconAction);
7094
text-decoration: none;
7195
border: none;
7296
transition: color 0.3s ease-in-out;
7397
background-color: transparent;
7498
cursor: pointer;
7599
}
76-
.content-inner button.icon-action {
77-
margin-top: 12px;
78-
}
79100
.content-inner .icon-action:hover {
80101
color: var(--iconActionHover);
81102
}

lib/ex_doc/formatter/html/templates/detail_template.eex

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
<a href="#<%=enc node.id %>" class="detail-link" data-no-tooltip aria-label="Link to this <%= pretty_type(node) %>">
77
<i class="ri-link-m" aria-hidden="true"></i>
88
</a>
9-
<h1 class="signature" translate="no"><%=h node.signature %></h1>
10-
<%= if node.source_url do %>
11-
<a href="<%= node.source_url %>" class="icon-action" rel="help" aria-label="View Source">
12-
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
13-
</a>
14-
<% end %>
15-
<%= for annotation <- node.annotations do %>
16-
<span class="note">(<%= annotation %>)</span>
17-
<% end %>
9+
<div class="heading-with-actions">
10+
<h1 class="signature" translate="no"><%=h node.signature %></h1>
11+
<%= for annotation <- node.annotations do %>
12+
<span class="note">(<%= annotation %>)</span>
13+
<% end %>
14+
<%= if node.source_url do %>
15+
<a href="<%= node.source_url %>" class="icon-action" rel="help" aria-label="View Source">
16+
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
17+
</a>
18+
<% end %>
19+
</div>
1820
</div>
1921
<%= if deprecated = node.deprecated do %>
2022
<div class="deprecated">

lib/ex_doc/formatter/html/templates/extra_template.eex

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
<%= sidebar_template(config, type, nodes_map) %>
33

44
<div id="top-content">
5-
<h1>
5+
<div class="heading-with-actions top-heading">
6+
<h1><%= node.title_content %></h1>
7+
<%= if type == :cheatmd do %>
8+
<button onclick="window.print()" title="Print Cheatsheet" class="icon-action" rel="print">
9+
<i class="ri-printer-line" aria-hidden="true"></i>
10+
<span class="sr-only">Print Cheatsheet</span>
11+
</button>
12+
<% end %>
613
<%= if node.source_url do %>
714
<a href="<%= node.source_url %>" title="View Source" class="icon-action" rel="help">
815
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
916
<span class="sr-only">View Source</span>
1017
</a>
1118
<% end %>
12-
<%= if type == :cheatmd do %>
13-
<button onclick="window.print()" title="Print Cheatsheet" class="icon-action" rel="print">
14-
<i class="ri-printer-line" aria-hidden="true"></i>
15-
<span class="sr-only">Print cheatsheet</span>
16-
</button>
17-
<% end %>
18-
19-
<span><%= node.title_content %></span>
20-
</h1>
19+
</div>
2120

2221
<%= if type == :livemd do %>
2322
<div class="livebook-badge-container">

lib/ex_doc/formatter/html/templates/module_template.eex

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
<%= sidebar_template(config, module.type, nodes_map) %>
33

44
<div id="top-content">
5-
<h1>
5+
<div class="heading-with-actions top-heading">
6+
<h1>
7+
<span translate="no"><%= module.title %></span> <%= module_type(module) %>
8+
<small class="app-vsn" translate="no">(<%= config.project %> v<%= config.version %>)</small>
9+
<%= for annotation <- module.annotations do %>
10+
<span class="note">(<%= annotation %>)</span>
11+
<% end %>
12+
</h1>
613
<%= if module.source_url do %>
714
<a href="<%= module.source_url %>" title="View Source" class="icon-action" rel="help">
815
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
916
<span class="sr-only">View Source</span>
1017
</a>
1118
<% end %>
12-
<span translate="no"><%= module.title %></span> <%= module_type(module) %>
13-
<small class="app-vsn" translate="no">(<%= config.project %> v<%= config.version %>)</small>
14-
<%= for annotation <- module.annotations do %>
15-
<span class="note">(<%= annotation %>)</span>
16-
<% end %>
17-
</h1>
19+
</div>
1820

1921
<%= if deprecated = module.deprecated do %>
2022
<div class="deprecated">
@@ -54,4 +56,5 @@
5456
</div>
5557
</section>
5658
<% end %>
59+
5760
<%= footer_template(config, module) %>

test/ex_doc/formatter/html_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ defmodule ExDoc.Formatter.HTMLTest do
108108
foo_content = EasyHTML.parse!(File.read!("#{c.tmp_dir}/html/readme-1.html"))["#content"]
109109
bar_content = EasyHTML.parse!(File.read!("#{c.tmp_dir}/html/readme-2.html"))["#content"]
110110

111-
assert to_string(foo_content["h1 > span"]) == "README foo"
112-
assert to_string(bar_content["h1 > span"]) == "README bar"
111+
assert to_string(foo_content["h1"]) == "README foo"
112+
assert to_string(bar_content["h1"]) == "README bar"
113113
end
114114

115115
test "warns when generating an index.html file with an invalid redirect",
@@ -499,14 +499,14 @@ defmodule ExDoc.Formatter.HTMLTest do
499499

500500
content = File.read!(tmp_dir <> "/html/plaintextfiles.html")
501501

502-
assert content =~ ~r{Plain Text Files</span>.*</h1>}s
502+
assert content =~ ~r{Plain Text Files</h1>}s
503503

504504
assert content =~
505505
~r{<p>Read the <a href="license.html">license</a> and the <a href="plaintext.html">plain-text file</a>.}
506506

507507
plain_text_file = File.read!(tmp_dir <> "/html/plaintext.html")
508508

509-
assert plain_text_file =~ ~r{PlainText</span>.*</h1>}s
509+
assert plain_text_file =~ ~r{PlainText</h1>}s
510510

511511
assert plain_text_file =~
512512
~r{<pre>\nThis is plain\n text and nothing\n.+\s+good bye\n</pre>}s
@@ -516,14 +516,14 @@ defmodule ExDoc.Formatter.HTMLTest do
516516

517517
license = File.read!(tmp_dir <> "/html/license.html")
518518

519-
assert license =~ ~r{LICENSE</span>.*</h1>}s
519+
assert license =~ ~r{LICENSE</h1>}s
520520

521521
assert license =~
522522
~s{<pre>\nLicensed under the Apache License, Version 2.0 (the &quot;License&quot;)}
523523

524524
content = File.read!(tmp_dir <> "/html/livebookfile.html")
525525

526-
assert content =~ ~r{<span>Title for Livebook Files</span>\s*</h1>}
526+
assert content =~ ~r{Title for Livebook Files</h1>}
527527

528528
assert content =~
529529
~s{<a href="https://github.com/elixir-lang/elixir/blob/main/test/fixtures/LivebookFile.livemd#L1" title="View Source"}
@@ -635,7 +635,7 @@ defmodule ExDoc.Formatter.HTMLTest do
635635

636636
content = File.read!(tmp_dir <> "/html/plaintextfiles.html")
637637

638-
assert content =~ ~r{Plain Text Files</span>.*</h1>}s
638+
assert content =~ ~r{Plain Text Files</h1>}s
639639

640640
assert content =~
641641
~r{<p>Read the <a href="linked-license.html">license</a> and the <a href="plain_text.html">plain-text file</a>.}

0 commit comments

Comments
 (0)