From 94184f381b84911509bf4478b2bbdd739bc4d295 Mon Sep 17 00:00:00 2001 From: saicaca Date: Sat, 7 Dec 2024 04:18:54 +0800 Subject: [PATCH] fix: fix TOC highlight for non-ASCII titles (#246) --- src/components/widget/TOC.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/widget/TOC.astro b/src/components/widget/TOC.astro index a9bac486..78a1d9e3 100644 --- a/src/components/widget/TOC.astro +++ b/src/components/widget/TOC.astro @@ -183,7 +183,7 @@ class TableOfContents extends HTMLElement { .find((element) => element instanceof HTMLAnchorElement); if (anchor) { - const id = anchor.hash?.substring(1); + const id = decodeURIComponent(anchor.hash?.substring(1)); const idx = this.headingIdxMap.get(id); if (idx !== undefined) { this.anchorNavTarget = this.headings[idx]; @@ -227,7 +227,7 @@ class TableOfContents extends HTMLElement { this.headings = new Array(this.tocEntries.length); 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; if (section instanceof HTMLElement) { this.headings[i] = section;