Skip to content

Commit 1b3bc87

Browse files
cursoragentmsukkari
andcommitted
feat(web): open chat links in new tab with external link icon
- Add custom anchor renderer to MarkdownRenderer component - Set target='_blank' and rel='noopener noreferrer' on all links - Display subtle ExternalLinkIcon (↗) after link text - Icon uses opacity-60 for muted appearance in both themes Fixes SOU-822 Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
1 parent 2fa86ff commit 1b3bc87

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/web/src/features/chat/components/chatThread/markdownRenderer.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SearchQueryParams } from '@/lib/types';
55
import { cn, createPathWithQueryParams } from '@/lib/utils';
66
import type { Element, Root } from "hast";
77
import { Schema as SanitizeSchema } from 'hast-util-sanitize';
8-
import { CopyIcon, SearchIcon } from 'lucide-react';
8+
import { CopyIcon, ExternalLinkIcon, SearchIcon } from 'lucide-react';
99
import type { Heading, Nodes } from "mdast";
1010
import { findAndReplace } from 'mdast-util-find-and-replace';
1111
import { useRouter } from 'next/navigation';
@@ -171,6 +171,21 @@ const MarkdownRendererComponent = forwardRef<HTMLDivElement, MarkdownRendererPro
171171
)
172172
}, []);
173173

174+
const renderAnchor = useCallback(({ href, children, ...rest }: React.JSX.IntrinsicElements['a']) => {
175+
return (
176+
<a
177+
href={href}
178+
target="_blank"
179+
rel="noopener noreferrer"
180+
className="inline-flex items-center gap-0.5"
181+
{...rest}
182+
>
183+
{children}
184+
<ExternalLinkIcon className="inline w-3 h-3 mb-0.5 opacity-60" />
185+
</a>
186+
);
187+
}, []);
188+
174189
const renderCode = useCallback(({ className, children, node, ...rest }: React.JSX.IntrinsicElements['code'] & { node?: Element }) => {
175190
const text = children?.toString().trimEnd() ?? '';
176191

@@ -239,6 +254,7 @@ const MarkdownRendererComponent = forwardRef<HTMLDivElement, MarkdownRendererPro
239254
components={{
240255
pre: renderPre,
241256
code: renderCode,
257+
a: renderAnchor,
242258
}}
243259
>
244260
{content}

0 commit comments

Comments
 (0)