Skip to content

Commit

Permalink
docs(js/convert-old-anchorid): add convertion for improper async fn a…
Browse files Browse the repository at this point in the history
…nchors
  • Loading branch information
hasezoey committed Apr 1, 2023
1 parent 53ba488 commit 19cc096
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/js/convert-old-anchorid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ window.addEventListener('DOMContentLoaded', () => {

// only operate on the old id's
if (!/^#\w+_\w+(?:-\w+)?$/i.test(anchor)) {
return;
return fixNoAsyncFn();
}

// in case there is no anchor, return without modifying the anchor
Expand Down Expand Up @@ -68,4 +68,25 @@ window.addEventListener('DOMContentLoaded', () => {
window.location.hash = `#${test}`;
}
}

// function to fix dox not recognizing async functions and resulting in inproper anchors
function fixNoAsyncFn() {
const anchorSlice = anchor.slice(1);
// dont modify anchor if it already exists
if (document.querySelector(`h3[id="${anchorSlice}"`)) {
return;
}

const tests = [
`${anchorSlice}()`
];

for (const test of tests) {
// have to use the "[id=]" selector because "#Something()" is not a valid selector (the "()" part)
const header = document.querySelector(`h3[id="${test}"]`);
if (header) {
window.location.hash = `#${test}`;
}
}
}
}, { once: true });

0 comments on commit 19cc096

Please sign in to comment.