fix: In page anchor links not working on shared docs

closes #2652
This commit is contained in:
Tom Moor
2021-10-12 23:12:47 -07:00
parent a6b3dbc894
commit 3a19c02e34
2 changed files with 23 additions and 2 deletions

View File

@@ -20,6 +20,27 @@ export function isInternalUrl(href: string) {
return false;
}
export function isHash(href: string) {
if (href[0] === "#") return true;
try {
const outline = new URL(window.location.href);
const parsed = new URL(href);
if (
outline.hostname === parsed.hostname &&
outline.pathname === parsed.pathname &&
!!parsed.hash
) {
return true;
}
} catch (e) {
// failed to parse as url
}
return false;
}
export function decodeURIComponentSafe(text: string) {
return text
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))