fix(article): TOC link not working when the heading starts with digits (#603)

This commit is contained in:
lonzzi 2022-06-11 06:39:16 +08:00 committed by GitHub
parent 9aa6b4925b
commit 7142de24cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,7 @@ function setupSmoothAnchors() {
let targetId = aElement.getAttribute("href").substring(1);
// The replace done on ':' is here for footnotes, as this character would otherwise interfere when used as a CSS selector.
let target = document.querySelector(`#${targetId.replace(":", "\\:")}`) as HTMLElement;
let target = document.getElementById(targetId.replace(":", "\\:")) as HTMLElement;
window.history.pushState({}, "", aElement.getAttribute("href"));
scrollTo({ top: target.offsetTop, behavior: "smooth" });