Skip to content

Commit 08a3382

Browse files
Merge pull request #2438 from buildkite/fix-h1-search
Add ids to h1 tags for search
2 parents 9e3ab41 + 8cc2c37 commit 08a3382

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/models/page/renderer.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def add_automatic_ids_to_headings(doc)
7575
h2_ids = []
7676
h3s_with_manual_ids = []
7777

78+
# h1 headers
79+
doc.search('./h1').each do |header|
80+
if (id = header['id']).blank?
81+
id = header['id'] = header.text.to_url
82+
end
83+
end
84+
85+
# h2 headers
7886
doc.search('./h2').each do |h2|
7987
if (id = h2['id']).blank?
8088
id = h2['id'] = h2.text.to_url

spec/models/page/renderer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
MD
99

1010
html = <<~HTML
11-
<h1>Page title</h1>
11+
<h1 id="page-title">Page title</h1>
1212
1313
<p>Some description</p>
1414
HTML

0 commit comments

Comments
 (0)