Skip to content

Commit

Permalink
Use decodeURIComponent but not encodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Mar 20, 2024
1 parent 9f259df commit 014c3a2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions web_src/js/markup/anchors.js
Expand Up @@ -25,7 +25,7 @@ export function initMarkupAnchors() {
const originalId = heading.id.replace(/^user-content-/, '');
const a = document.createElement('a');
a.classList.add('anchor');
a.setAttribute('href', `#${encodeURIComponent(originalId)}`);
a.setAttribute('href', `#${decodeURIComponent(originalId)}`);
a.innerHTML = svg('octicon-link');
a.addEventListener('click', (e) => {
scrollToAnchor(e.currentTarget.getAttribute('href'), false);
Expand All @@ -38,8 +38,8 @@ export function initMarkupAnchors() {
const href = a.getAttribute('href');
if (!href.startsWith('#user-content-')) continue;
const originalId = href.replace(/^#user-content-/, '');
a.setAttribute('href', `#${originalId}`);
if (a.closest('.markup').querySelectorAll(`a[name="${originalId}"]`).length !== 1) {
a.setAttribute('href', `#${decodeURIComponent(originalId)}`);
if (a.closest('.markup').querySelectorAll(`a[name="${decodeURIComponent(originalId)}"]`).length !== 1) {
a.addEventListener('click', (e) => {
scrollToAnchor(e.currentTarget.getAttribute('href'), false);
});
Expand Down

0 comments on commit 014c3a2

Please sign in to comment.