From ac05e205ba90c5e02b40586b18ae7174a0e3bda8 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Sat, 9 Mar 2024 08:40:05 +0800 Subject: [PATCH] Use more specific selector for `name` links (#29679) (#29681) Backport #29679 by @silverwind Followup https://github.com/go-gitea/gitea/pull/29305. As per discussion in https://github.com/go-gitea/gitea/pull/29666#discussion_r1517506422, 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 (cherry picked from commit 25b0c99a41e9024d439deaa55be7ba87f6cd557f) --- web_src/js/markup/anchors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/markup/anchors.js b/web_src/js/markup/anchors.js index 03934ea215..6cf83eb428 100644 --- a/web_src/js/markup/anchors.js +++ b/web_src/js/markup/anchors.js @@ -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); });