Skip to content

Commit f183f9b

Browse files
committed
Make headers/method names directly linkable instead of using pilcrow items
1 parent 633e589 commit f183f9b

File tree

7 files changed

+45
-85
lines changed

7 files changed

+45
-85
lines changed

lib/rdoc/generator/template/aliki/class.rhtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<%- if section.title then %>
4242
<header class="documentation-section-title">
4343
<h2>
44-
<%= section.title %>
44+
<a href="#<%= section.aref %>"><%= section.title %></a>
4545
</h2>
4646
</header>
4747
<%- end %>
@@ -55,7 +55,7 @@
5555
<%- unless constants.empty? then %>
5656
<section class="constants-list">
5757
<header>
58-
<h3 id="constants">Constants</h3>
58+
<h3 id="constants"><a href="#constants">Constants</a></h3>
5959
</header>
6060
<dl>
6161
<%- constants.each do |const| %>
@@ -80,7 +80,7 @@
8080
<%- unless attributes.empty? then %>
8181
<section class="attribute-method-details method-section">
8282
<header>
83-
<h3 id="attributes">Attributes</h3>
83+
<h3 id="attributes"><a href="#attributes">Attributes</a></h3>
8484
</header>
8585

8686
<%- attributes.each do |attrib| %>
@@ -115,7 +115,7 @@
115115
next if methods.empty? %>
116116
<section id="<%= visibility %>-<%= type %>-<%= section.aref %>-method-details" class="method-section anchor-link">
117117
<header>
118-
<h3 id="<%= visibility %>-<%= type %>-methods"><%= visibility.to_s.capitalize %> <%= type.capitalize %> Methods</h3>
118+
<h3 id="<%= visibility %>-<%= type %>-methods"><a href="#<%= visibility %>-<%= type %>-methods"><%= visibility.to_s.capitalize %> <%= type.capitalize %> Methods</a></h3>
119119
</header>
120120

121121
<%- methods.each do |method| %>

lib/rdoc/generator/template/aliki/css/rdoc.css

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -225,35 +225,6 @@ body.has-toc {
225225
}
226226

227227
/* 3. Typography */
228-
h1 span,
229-
h2 span,
230-
h3 span,
231-
h4 span,
232-
h5 span,
233-
h6 span {
234-
position: relative;
235-
display: none;
236-
padding-left: 1em;
237-
line-height: 0;
238-
vertical-align: baseline;
239-
font-size: 10px;
240-
}
241-
242-
h1 span { top: -1.3em; }
243-
h2 span { top: -1.2em; }
244-
h3 span { top: -1.0em; }
245-
h4 span { top: -0.8em; }
246-
h5 span { top: -0.5em; }
247-
h6 span { top: -0.5em; }
248-
249-
h1:hover span,
250-
h2:hover span,
251-
h3:hover span,
252-
h4:hover span,
253-
h5:hover span,
254-
h6:hover span {
255-
display: inline;
256-
}
257228

258229
/* 4. Links */
259230
a {
@@ -797,6 +768,26 @@ main h5, main h6 {
797768
margin-bottom: var(--space-2);
798769
}
799770

771+
/* Heading links */
772+
main h1 a,
773+
main h2 a,
774+
main h3 a,
775+
main h4 a,
776+
main h5 a,
777+
main h6 a {
778+
color: inherit;
779+
text-decoration: none;
780+
}
781+
782+
main h1 a:hover,
783+
main h2 a:hover,
784+
main h3 a:hover,
785+
main h4 a:hover,
786+
main h5 a:hover,
787+
main h6 a:hover {
788+
text-decoration: underline;
789+
}
790+
800791
/* Syntax Highlighting - Light Theme */
801792
.ruby-constant { color: var(--code-orange); }
802793
.ruby-keyword { color: var(--code-red); }
@@ -1012,18 +1003,6 @@ main .method-heading .method-args {
10121003
font-weight: var(--font-weight-normal);
10131004
}
10141005

1015-
main .method-heading::after {
1016-
content: '¶';
1017-
position: absolute;
1018-
visibility: hidden;
1019-
color: var(--color-accent-primary);
1020-
font-size: 0.5em;
1021-
}
1022-
1023-
main .method-heading:hover::after {
1024-
visibility: visible;
1025-
}
1026-
10271006
main .method-controls {
10281007
line-height: 20px;
10291008
float: right;

lib/rdoc/generator/template/aliki/js/aliki.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function generateToc() {
191191
const link = document.createElement('a');
192192
link.href = `#${heading.id}`;
193193
link.className = 'toc-link';
194-
link.textContent = heading.textContent.replace(/.*$/, '').trim(); // Remove pilcrow link
194+
link.textContent = heading.textContent.trim();
195195
link.setAttribute('data-target', heading.id);
196196

197197
li.appendChild(link);

lib/rdoc/markup/to_html.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,13 @@ def accept_heading(heading)
312312
else
313313
"\n<h#{level}>"
314314
end
315-
@res << to_html(heading.text)
316-
unless @options.pipe then
317-
@res << "<span><a href=\"##{label}\">&para;</a></span>"
315+
316+
if @options.pipe
317+
@res << to_html(heading.text)
318+
else
319+
@res << "<a href=\"##{label}\">#{to_html(heading.text)}</a>"
318320
end
321+
319322
@res << "</h#{level}>\n"
320323
end
321324

test/rdoc/generator/darkfish_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_generate
125125
klassnav
126126
)
127127

128-
assert_match(/<h1 id="class-Klass-label-Heading\+1">Heading 1(?!\.)/,
128+
assert_match(/<h1 id="class-Klass-label-Heading\+1"><a href="#class-Klass-label-Heading\+1">Heading 1<\/a>(?!\.)/,
129129
klass[%r[<section class=\"description\">.*</section>]m])
130130
toc = File.binread('table_of_contents.html')
131131
assert_match(
@@ -171,7 +171,7 @@ def test_generate_index_with_main_page
171171
index_html = File.binread('index.html')
172172

173173
assert_include index_html, "<h3>Table of Contents</h3>"
174-
assert_include index_html, '<h1 id="label-Heading+1">Heading 1'
174+
assert_include index_html, '<h1 id="label-Heading+1"><a href="#label-Heading+1">Heading 1</a>'
175175
# When there's a main page, the default description should not be shown
176176
assert_not_include index_html, 'This is the API documentation for My awesome Ruby project.'
177177
end

test/rdoc/generator/markup_test.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def test_cvs_url
3838
def test_description
3939
@comment = '= Hello'
4040

41-
links = '<span><a href="#label-Hello">&para;</a></span>'
42-
43-
assert_equal "\n<h1 id=\"label-Hello\">Hello#{links}</h1>\n", description
41+
assert_equal "\n<h1 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h1>\n", description
4442
end
4543

4644
def test_formatter

test/rdoc/markup/to_html_test.rb

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,34 @@ def accept_document
2424
end
2525

2626
def accept_heading
27-
links = '<span><a href="#label-Hello">&para;</a></span>'
28-
expected = "\n<h5 id=\"label-Hello\">Hello#{links}</h5>\n"
29-
30-
assert_equal expected, @to.res.join
27+
assert_equal "\n<h5 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h5>\n", @to.res.join
3128
end
3229

3330
def accept_heading_1
34-
links = '<span><a href="#label-Hello">&para;</a></span>'
35-
36-
assert_equal "\n<h1 id=\"label-Hello\">Hello#{links}</h1>\n", @to.res.join
31+
assert_equal "\n<h1 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h1>\n", @to.res.join
3732
end
3833

3934
def accept_heading_2
40-
links = '<span><a href="#label-Hello">&para;</a></span>'
41-
42-
assert_equal "\n<h2 id=\"label-Hello\">Hello#{links}</h2>\n", @to.res.join
35+
assert_equal "\n<h2 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h2>\n", @to.res.join
4336
end
4437

4538
def accept_heading_3
46-
links = '<span><a href="#label-Hello">&para;</a></span>'
47-
48-
assert_equal "\n<h3 id=\"label-Hello\">Hello#{links}</h3>\n", @to.res.join
39+
assert_equal "\n<h3 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h3>\n", @to.res.join
4940
end
5041

5142
def accept_heading_4
52-
links = '<span><a href="#label-Hello">&para;</a></span>'
53-
54-
assert_equal "\n<h4 id=\"label-Hello\">Hello#{links}</h4>\n", @to.res.join
43+
assert_equal "\n<h4 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h4>\n", @to.res.join
5544
end
5645

5746
def accept_heading_b
58-
links = '<span><a href="#label-Hello">&para;</a></span>'
5947
inner = "<strong>Hello</strong>"
6048

61-
assert_equal "\n<h1 id=\"label-Hello\">#{inner}#{links}</h1>\n",
49+
assert_equal "\n<h1 id=\"label-Hello\"><a href=\"#label-Hello\">#{inner}</a></h1>\n",
6250
@to.res.join
6351
end
6452

6553
def accept_heading_suppressed_crossref
66-
links = '<span><a href="#label-Hello">&para;</a></span>'
67-
68-
assert_equal "\n<h1 id=\"label-Hello\">Hello#{links}</h1>\n", @to.res.join
54+
assert_equal "\n<h1 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h1>\n", @to.res.join
6955
end
7056

7157
def accept_list_end_bullet
@@ -341,9 +327,7 @@ def test_accept_heading_7
341327

342328
@to.accept_heading @RM::Heading.new(7, 'Hello')
343329

344-
links = '<span><a href="#label-Hello">&para;</a></span>'
345-
346-
assert_equal "\n<h6 id=\"label-Hello\">Hello#{links}</h6>\n", @to.res.join
330+
assert_equal "\n<h6 id=\"label-Hello\"><a href=\"#label-Hello\">Hello</a></h6>\n", @to.res.join
347331
end
348332

349333
def test_accept_heading_aref_class
@@ -352,9 +336,7 @@ def test_accept_heading_aref_class
352336

353337
@to.accept_heading head(1, 'Hello')
354338

355-
links = '<span><a href="#class-Foo-label-Hello">&para;</a></span>'
356-
357-
assert_equal "\n<h1 id=\"class-Foo-label-Hello\">Hello#{links}</h1>\n",
339+
assert_equal "\n<h1 id=\"class-Foo-label-Hello\"><a href=\"#class-Foo-label-Hello\">Hello</a></h1>\n",
358340
@to.res.join
359341
end
360342

@@ -364,9 +346,7 @@ def test_accept_heading_aref_method
364346

365347
@to.accept_heading @RM::Heading.new(1, 'Hello')
366348

367-
links = '<span><a href="#method-i-foo-label-Hello">&para;</a></span>'
368-
369-
assert_equal "\n<h1 id=\"method-i-foo-label-Hello\">Hello#{links}</h1>\n",
349+
assert_equal "\n<h1 id=\"method-i-foo-label-Hello\"><a href=\"#method-i-foo-label-Hello\">Hello</a></h1>\n",
370350
@to.res.join
371351
end
372352

@@ -427,7 +407,7 @@ def test_accept_heading_output_decoration
427407

428408
@to.accept_heading @RM::Heading.new(1, 'Hello')
429409

430-
assert_equal "\n<h1>Hello<span><a href=\"#label-Hello\">&para;</a></span></h1>\n", @to.res.join
410+
assert_equal "\n<h1><a href=\"#label-Hello\">Hello</a></h1>\n", @to.res.join
431411
end
432412

433413
def test_accept_heading_output_decoration_with_pipe

0 commit comments

Comments
 (0)