Parameterize ToC titles, remove html tags from slug (thx seweil), fixes #904

This commit is contained in:
Robert Lord
2017-11-23 10:14:03 -08:00
parent 2056b4a4b9
commit 7ef0fd4327
2 changed files with 3 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ class UniqueHeadCounter < Middleman::Renderers::MiddlemanRedcarpetHTML
@head_count = {}
end
def header(text, header_level)
friendly_text = text.parameterize
friendly_text = text.gsub(/<[^<]+>/,"").parameterize
@head_count[friendly_text] ||= 0
@head_count[friendly_text] += 1
if @head_count[friendly_text] > 1

View File

@@ -72,12 +72,12 @@ under the License.
<div id="toc" class="toc-list-h1">
<% toc_data(page_content).each do |h1| %>
<li>
<a href="#<%= h1[:id] %>" class="toc-h1 toc-link" data-title="<%= h1[:content] %>"><%= h1[:content] %></a>
<a href="#<%= h1[:id] %>" class="toc-h1 toc-link" data-title="<%= h1[:content].to_s.parameterize %>"><%= h1[:content] %></a>
<% if h1[:children].length > 0 %>
<ul class="toc-list-h2">
<% h1[:children].each do |h2| %>
<li>
<a href="#<%= h2[:id] %>" class="toc-h2 toc-link" data-title="<%= h2[:content] %>"><%= h2[:content] %></a>
<a href="#<%= h2[:id] %>" class="toc-h2 toc-link" data-title="<%= h2[:content].to_s.parameterize %>"><%= h2[:content] %></a>
</li>
<% end %>
</ul>