fix: fix TOC highlight for non-ASCII titles (#246)

This commit is contained in:
saicaca
2024-12-07 04:18:54 +08:00
parent eb3f9f2676
commit 94184f381b

View File

@@ -183,7 +183,7 @@ class TableOfContents extends HTMLElement {
.find((element) => element instanceof HTMLAnchorElement); .find((element) => element instanceof HTMLAnchorElement);
if (anchor) { if (anchor) {
const id = anchor.hash?.substring(1); const id = decodeURIComponent(anchor.hash?.substring(1));
const idx = this.headingIdxMap.get(id); const idx = this.headingIdxMap.get(id);
if (idx !== undefined) { if (idx !== undefined) {
this.anchorNavTarget = this.headings[idx]; this.anchorNavTarget = this.headings[idx];
@@ -227,7 +227,7 @@ class TableOfContents extends HTMLElement {
this.headings = new Array(this.tocEntries.length); this.headings = new Array(this.tocEntries.length);
for (let i = 0; i < this.tocEntries.length; i++) { for (let i = 0; i < this.tocEntries.length; i++) {
const id = this.tocEntries[i].hash?.substring(1); const id = decodeURIComponent(this.tocEntries[i].hash?.substring(1));
const section = document.getElementById(id)?.parentElement; const section = document.getElementById(id)?.parentElement;
if (section instanceof HTMLElement) { if (section instanceof HTMLElement) {
this.headings[i] = section; this.headings[i] = section;