Skip to content

Commit b2119b0

Browse files
committedJul 5, 2018
Fix ToC issues, fix #995
1 parent e621be0 commit b2119b0

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed
 

‎lib/nesting_unique_head.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize
88
end
99

1010
def header(text, header_level)
11-
friendly_text = text.parameterize
11+
friendly_text = text.gsub(/<[^>]*>/,"").parameterize
1212
@@headers_history[header_level] = text.parameterize
1313

1414
if header_level > 1

‎lib/toc_data.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def toc_data(page_content)
99
headers.push({
1010
id: header.attribute('id').to_s,
1111
content: header.children,
12+
title: header.children.to_s.gsub(/<[^>]*>/, ''),
1213
level: header.name[1].to_i,
1314
children: []
1415
})
@@ -27,4 +28,4 @@ def toc_data(page_content)
2728
end
2829
end
2930
headers
30-
end
31+
end

‎lib/unique_head.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def initialize
77
@head_count = {}
88
end
99
def header(text, header_level)
10-
friendly_text = text.gsub(/<[^<]+>/,"").parameterize
10+
friendly_text = text.gsub(/<[^>]*>/,"").parameterize
1111
if friendly_text.strip.length == 0
1212
# Looks like parameterize removed the whole thing! It removes many unicode
1313
# characters like Chinese and Russian. To get a unique URL, let's just

‎source/javascripts/app/_toc.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;(function () {
44
'use strict';
55

6-
var htmlPattern = /<[^>]*>/g;
6+
var htmlPattern = /<[^>]*>/g;
77
var loaded = false;
88

99
var debounce = function(func, waitTime) {
@@ -67,7 +67,6 @@
6767
}
6868

6969
var $best = $toc.find("[href='" + best + "']").first();
70-
var joinedTitle = $best.data("title") + " – " + originalTitle;
7170
if (!$best.hasClass("active")) {
7271
// .active is applied to the ToC link we're currently on, and its parent <ul>s selected by tocListSelector
7372
// .active-expanded is applied to the ToC links that are parents of this one
@@ -81,8 +80,12 @@
8180
if (window.history.replaceState) {
8281
window.history.replaceState(null, "", best);
8382
}
84-
// TODO remove classnames
85-
document.title = joinedTitle.replace(htmlPattern, '');
83+
var thisTitle = $best.data("title")
84+
if (thisTitle !== undefined && thisTitle.length > 0) {
85+
document.title = thisTitle + " – " + originalTitle;
86+
} else {
87+
document.title = originalTitle;
88+
}
8689
}
8790
};
8891

‎source/layouts/layout.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ under the License.
7272
<ul id="toc" class="toc-list-h1">
7373
<% toc_data(page_content).each do |h1| %>
7474
<li>
75-
<a href="#<%= h1[:id] %>" class="toc-h1 toc-link" data-title="<%= h1[:content].to_s.parameterize %>"><%= h1[:content] %></a>
75+
<a href="#<%= h1[:id] %>" class="toc-h1 toc-link" data-title="<%= h1[:title] %>"><%= h1[:content] %></a>
7676
<% if h1[:children].length > 0 %>
7777
<ul class="toc-list-h2">
7878
<% h1[:children].each do |h2| %>
7979
<li>
80-
<a href="#<%= h2[:id] %>" class="toc-h2 toc-link" data-title="<%= h2[:content].to_s.parameterize %>"><%= h2[:content] %></a>
80+
<a href="#<%= h2[:id] %>" class="toc-h2 toc-link" data-title="<%= h2[:title] %>"><%= h2[:content] %></a>
8181
</li>
8282
<% end %>
8383
</ul>

0 commit comments

Comments
 (0)
Please sign in to comment.