Skip to content

Commit 1c232e4

Browse files
committed
Fix JavaScript error when clicking a footnote link.
1 parent 98eb32c commit 1c232e4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

web_src/js/markup/anchors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const hasPrefix = (str: string): boolean => str.startsWith('user-content-');
66

77
// scroll to anchor while respecting the `user-content` prefix that exists on the target
88
function scrollToAnchor(encodedId: string): void {
9-
if (!encodedId) return;
9+
// Ignore the footnote case, as the link is rendered by the backend.
10+
if (!encodedId || encodedId.startsWith('fn:') || encodedId.startsWith('fnref:')) return;
1011
const id = decodeURIComponent(encodedId);
1112
const prefixedId = addPrefix(id);
1213
let el = document.querySelector(`#${prefixedId}`);
@@ -55,6 +56,7 @@ export function initMarkupAnchors(): void {
5556

5657
for (const a of markupEl.querySelectorAll<HTMLAnchorElement>('a[href^="#"]')) {
5758
a.addEventListener('click', (e) => {
59+
console.log(e.currentTarget)
5860
scrollToAnchor((e.currentTarget as HTMLAnchorElement).getAttribute('href')?.substring(1));
5961
});
6062
}

0 commit comments

Comments
 (0)