|
40 | 40 | html = settings.title + ' <'+settings.listType+' class="jekyll-toc">';
|
41 | 41 |
|
42 | 42 | var back_to_top = function(id) {
|
43 |
| - return '<a href="#' +id+ '" title="'+settings.backToTopTitle+'" class="jekyll-toc-anchor jekyll-toc-back-to-top"><span class="jekyll-toc-icon">'+settings.backToTopText+'</span></a>'; |
| 43 | + return '<a href="#' +fixedEncodeURIComponent(id)+ '" title="'+settings.backToTopTitle+'" class="jekyll-toc-anchor jekyll-toc-back-to-top"><span class="jekyll-toc-icon">'+settings.backToTopText+'</span></a>'; |
44 | 44 | }
|
45 | 45 |
|
46 | 46 | var link_here = function(id) {
|
47 |
| - return '<a href="#' +id+ '" title="'+settings.linkHereTitle+'" class="jekyll-toc-anchor jekyll-toc-link-here"><span class="jekyll-toc-icon">'+settings.linkHereText+'</span></a>'; |
| 47 | + return '<a href="#' +fixedEncodeURIComponent(id)+ '" title="'+settings.linkHereTitle+'" class="jekyll-toc-anchor jekyll-toc-link-here"><span class="jekyll-toc-icon">'+settings.linkHereText+'</span></a>'; |
| 48 | + } |
| 49 | + |
| 50 | + function fixedEncodeURIComponent (str) { |
| 51 | + return encodeURIComponent(str).replace(/[!'()*]/g, function(c) { |
| 52 | + return '%' + c.charCodeAt(0).toString(16); |
| 53 | + }); |
48 | 54 | }
|
49 | 55 |
|
50 | 56 | function force_update_hash(hash) {
|
|
59 | 65 | this_level = get_level(header);
|
60 | 66 | var header_id = $(header).attr('id');
|
61 | 67 | if (this_level === level) // same level as before; same indenting
|
62 |
| - html += "<li><a href='#" + header.id + "'>" + header.innerHTML + "</a>"; |
| 68 | + html += "<li><a href='#" + fixedEncodeURIComponent(header.id) + "'>" + header.innerHTML + "</a>"; |
63 | 69 | else if (this_level <= level){ // higher level than before; end parent ol
|
64 | 70 | for(i = this_level; i < level; i++) {
|
65 | 71 | html += "</li></"+settings.listType+">"
|
66 | 72 | }
|
67 |
| - html += "<li><a href='#" + header.id + "'>" + header.innerHTML + "</a>"; |
| 73 | + html += "<li><a href='#" + fixedEncodeURIComponent(header.id) + "'>" + header.innerHTML + "</a>"; |
68 | 74 | }
|
69 | 75 | else if (this_level > level) { // lower level than before; expand the previous to contain a ol
|
70 | 76 | for(i = this_level; i > level; i--) {
|
71 | 77 | html += "<"+settings.listType+"><li>"
|
72 | 78 | }
|
73 |
| - html += "<a href='#" + header.id + "'>" + header.innerHTML + "</a>"; |
| 79 | + html += "<a href='#" + fixedEncodeURIComponent(header.id) + "'>" + header.innerHTML + "</a>"; |
74 | 80 | }
|
75 | 81 | level = this_level; // update for the next one
|
76 | 82 |
|
|
92 | 98 | if (settings.linkHeader) {
|
93 | 99 | $(header).addClass('jekyll-toc-header');
|
94 | 100 | $(header).children('span.jekyll-toc-wrapper').on( 'click', function( ) {
|
95 |
| - force_update_hash(header_id); |
| 101 | + force_update_hash(fixedEncodeURIComponent(header_id)); |
96 | 102 | });
|
97 | 103 | }
|
98 | 104 | });
|
|
0 commit comments