Skip to content

Commit 2e2670c

Browse files
Niels van BrakelNiels van Brakel
authored andcommitted
fixed an bug where special chars would break the highlighting
1 parent 54c9fef commit 2e2670c

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

assets/css/common/post-single.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
}
305305

306306
.active {
307-
font-weight: 500;
307+
font-weight: 600;
308308
}
309309

310310
.toc ul {

layouts/partials/toc.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
elements = document.querySelectorAll('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]');
102102
// Make the first header active
103103
activeElement = elements[0];
104-
document.querySelector(`.inner ul li a[href="#${activeElement.getAttribute('id')}"]`).classList.add('active');
104+
const id = encodeURI(activeElement.getAttribute('id')).toLowerCase();
105+
document.querySelector(`.inner ul li a[href="#${id}"]`).classList.add('active');
105106
}, false);
106107

107108
window.addEventListener('resize', function(event) {
@@ -118,10 +119,11 @@
118119
}) || activeElement
119120

120121
elements.forEach(element => {
121-
if (element === activeElement ){
122-
document.querySelector(`.inner ul li a[href="#${element.getAttribute('id')}"]`).classList.add('active');
122+
const id = encodeURI(element.getAttribute('id')).toLowerCase();
123+
if (element === activeElement){
124+
document.querySelector(`.inner ul li a[href="#${id}"]`).classList.add('active');
123125
} else {
124-
document.querySelector(`.inner ul li a[href="#${element.getAttribute('id')}"]`).classList.remove('active');
126+
document.querySelector(`.inner ul li a[href="#${id}"]`).classList.remove('active');
125127
}
126128
})
127129
}, false);

0 commit comments

Comments
 (0)