Allow root absolute links
This commit is contained in:
parent
af50754aff
commit
052bc45260
1 changed files with 6 additions and 2 deletions
|
|
@ -262,6 +262,9 @@
|
||||||
const d = dest.trim();
|
const d = dest.trim();
|
||||||
if (/^https?:\/\//i.test(d)) return d;
|
if (/^https?:\/\//i.test(d)) return d;
|
||||||
if (/^mailto:/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 (/^[a-z][a-z0-9+.-]*:/i.test(d)) return null;
|
||||||
if (/\S\.\S/.test(d)) return `https://${d}`;
|
if (/\S\.\S/.test(d)) return `https://${d}`;
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -585,10 +588,11 @@
|
||||||
{#snippet renderInlines(inlines: Inline[])}
|
{#snippet renderInlines(inlines: Inline[])}
|
||||||
{#each inlines as inline (inline)}
|
{#each inlines as inline (inline)}
|
||||||
{#if inline.type === "link"}
|
{#if inline.type === "link"}
|
||||||
|
{@const internal = inline.href.startsWith("/")}
|
||||||
<a
|
<a
|
||||||
href={inline.href}
|
href={inline.href}
|
||||||
target="_blank"
|
target={internal ? undefined : "_blank"}
|
||||||
rel="noopener noreferrer"
|
rel={internal ? undefined : "noopener noreferrer"}
|
||||||
class="text-brand hover:underline break-all">{inline.label}</a
|
class="text-brand hover:underline break-all">{inline.label}</a
|
||||||
>
|
>
|
||||||
{:else if inline.type === "mention"}
|
{:else if inline.type === "mention"}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue