From 19cc0965663a7f45df8139abd55ccc7ec41cfcc6 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sat, 1 Apr 2023 12:08:19 +0200 Subject: [PATCH] docs(js/convert-old-anchorid): add convertion for improper async fn anchors --- docs/js/convert-old-anchorid.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/js/convert-old-anchorid.js b/docs/js/convert-old-anchorid.js index fd8054019c2..5f651092f6e 100644 --- a/docs/js/convert-old-anchorid.js +++ b/docs/js/convert-old-anchorid.js @@ -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 @@ -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 });