Skip to content

Commit

Permalink
Changed file anchor.js to fix the bug in issue go-gitea#29196
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMatiasCarvalho committed Feb 20, 2024
1 parent ade1110 commit 12f97a2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web_src/js/markup/anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ export function initMarkupAnchors() {
});
heading.prepend(a);
}
for (const anchor of document.querySelectorAll('.markup [dir="auto"] > a[href^="#"][rel="nofollow"]')) {
const originalId = anchor.getAttribute('href').replace(/^#user-content-/, '');
anchor.setAttribute('href', `#${encodeURIComponent(originalId)}`);
const anchorDest = document.getElementsByName(originalId);
if (anchorDest && anchorDest.length === 1) {
anchor.addEventListener('click', (e) => {
e.scrollIntoView();
});
} else {
anchor.addEventListener('click', (e) => {
scrollToAnchor(e.currentTarget.getAttribute('href'), false);
});
}
}

scrollToAnchor(window.location.hash, true);
}

0 comments on commit 12f97a2

Please sign in to comment.