diff --git a/src/lib/components/chat/Messages/Markdown/MarkdownInlineTokens.svelte b/src/lib/components/chat/Messages/Markdown/MarkdownInlineTokens.svelte index 365723373..b187ecfe2 100644 --- a/src/lib/components/chat/Messages/Markdown/MarkdownInlineTokens.svelte +++ b/src/lib/components/chat/Messages/Markdown/MarkdownInlineTokens.svelte @@ -4,6 +4,7 @@ import type { Token } from 'marked'; import { getContext } from 'svelte'; + import { goto } from '$app/navigation'; const i18n = getContext('i18n'); @@ -24,6 +25,27 @@ export let tokens: Token[]; export let sourceIds = []; export let onSourceClick: Function = () => {}; + + /** + * Handle link clicks - intercept same-origin app URLs for in-app navigation + */ + const handleLinkClick = (e: MouseEvent, href: string) => { + try { + const url = new URL(href, window.location.origin); + // Check if same origin and an in-app route + if ( + url.origin === window.location.origin && + (url.pathname.startsWith('/notes/') || + url.pathname.startsWith('/c/') || + url.pathname.startsWith('/channels/')) + ) { + e.preventDefault(); + goto(url.pathname + url.search + url.hash); + } + } catch { + // Invalid URL, let browser handle it + } + }; {#each tokens as token, tokenIdx (tokenIdx)} @@ -33,11 +55,11 @@ {:else if token.type === 'link'} {#if token.tokens} - + handleLinkClick(e, token.href)}> {:else} - {token.text} + handleLinkClick(e, token.href)}>{token.text} {/if} {:else if token.type === 'image'} {token.text}