Skip to content

Commit

Permalink
Use more specific selector for name links (#29679) (#29681)
Browse files Browse the repository at this point in the history
Backport #29679 by @silverwind

Followup go-gitea/gitea#29305. As per discussion
in go-gitea/gitea#29666 (comment),
make this selector only search in the current `.markup` document, as
there can be multiples displayed at the same time.

@DanielMatiasCarvalho maybe you can review.

Co-authored-by: silverwind <me@silverwind.io>
(cherry picked from commit 25b0c99a41e9024d439deaa55be7ba87f6cd557f)
  • Loading branch information
GiteaBot authored and earl-warren committed Mar 10, 2024
1 parent 03caefb commit ac05e20
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion web_src/js/markup/anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function initMarkupAnchors() {
if (!href.startsWith('#user-content-')) continue;
const originalId = href.replace(/^#user-content-/, '');
a.setAttribute('href', `#${encodeURIComponent(originalId)}`);
if (document.getElementsByName(originalId).length !== 1) {
if (a.closest('.markup').querySelectorAll(`a[name="${originalId}"]`).length !== 1) {
a.addEventListener('click', (e) => {
scrollToAnchor(e.currentTarget.getAttribute('href'), false);
});
Expand Down

0 comments on commit ac05e20

Please sign in to comment.