From b4948b680f26721203371f3c9b1a52b55f8a9621 Mon Sep 17 00:00:00 2001 From: icanrealizeum Date: Sun, 31 Jul 2016 15:18:36 +0300 Subject: [PATCH] Fixes #156 - anchors are now URI encoded also fixes https://github.com/rust-lang/book/issues/166 anchors duplication Thanks @azerupi for mentoring in #156 ! Cheers! --- src/theme/book.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/theme/book.js b/src/theme/book.js index 6fceb7d5..231b02ab 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -57,7 +57,9 @@ $( document ).ready(function() { var wrapper = $(""); wrapper.attr("name", $(this).text()); // Add so that when you click the link actually shows up in the url bar... - wrapper.attr("href", $(location).attr('href') + "#" + $(this).text()); + // Remove any existing anchor then append the new one + // ensuring eg. no spaces are present within it ie. they become %20 + wrapper.attr("href", $(location).attr('href').split("#")[0] + "#" + encodeURIComponent($(this).text().trim()) ); return wrapper; });