]> source.dussan.org Git - gitea.git/commitdiff
Use more specific selector for `name` links (#29679) (#29681)
authorGiteabot <teabot@gitea.io>
Sat, 9 Mar 2024 00:40:05 +0000 (08:40 +0800)
committerGitHub <noreply@github.com>
Sat, 9 Mar 2024 00:40:05 +0000 (08:40 +0800)
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 <me@silverwind.io>
web_src/js/markup/anchors.js

index 03934ea215fab274ecdcdb93403a797a4a406021..6cf83eb428b854e8c50c6516c622888dfdc0fa1c 100644 (file)
@@ -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);
       });