Skip to content

Commit ecae442

Browse files
authored
Merge pull request #173 from HParker/slugify-section-anchors
slugify section headers
2 parents b91f817 + f26f41f commit ecae442

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/theme/book.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ $( document ).ready(function() {
5555
// Add anchors for all content headers
5656
content.find("h1, h2, h3, h4, h5").wrap(function(){
5757
var wrapper = $("<a class=\"header\">");
58-
wrapper.attr("name", $(this).text());
58+
var header_name = $(this).text().trim().replace(/\W/g, '-')
59+
wrapper.attr("name", header_name);
5960
// Add so that when you click the link actually shows up in the url bar...
6061
// Remove any existing anchor then append the new one
6162
// ensuring eg. no spaces are present within it ie. they become %20
62-
wrapper.attr("href", $(location).attr('href').split("#")[0] + "#" + encodeURIComponent($(this).text().trim()) );
63+
wrapper.attr("href", $(location).attr('href').split("#")[0] + "#" + header_name );
6364
return wrapper;
6465
});
6566

0 commit comments

Comments
 (0)