From 052bc4526059856b63d7f61ff81a95b58650abc7 Mon Sep 17 00:00:00 2001 From: dtonon Date: Thu, 21 May 2026 23:42:02 +0100 Subject: [PATCH] Allow root absolute links --- src/lib/components/PostContent.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/components/PostContent.svelte b/src/lib/components/PostContent.svelte index 0de1343..234dcf8 100644 --- a/src/lib/components/PostContent.svelte +++ b/src/lib/components/PostContent.svelte @@ -262,6 +262,9 @@ const d = dest.trim(); if (/^https?:\/\//i.test(d)) return d; if (/^mailto:/i.test(d)) return d; + // Root-relative internal link. The negative lookahead rejects + // protocol-relative URLs (//host), which the browser treats as external. + if (/^\/(?!\/)/.test(d)) return d; if (/^[a-z][a-z0-9+.-]*:/i.test(d)) return null; if (/\S\.\S/.test(d)) return `https://${d}`; return null; @@ -585,10 +588,11 @@ {#snippet renderInlines(inlines: Inline[])} {#each inlines as inline (inline)} {#if inline.type === "link"} + {@const internal = inline.href.startsWith("/")} {inline.label} {:else if inline.type === "mention"}