Skip to content

An AI-powered search engine with a generative UI

Add rehype-external-links plugin to MemoizedReactMarkdown

Yoshiki Miura91a912edf517
diff --git a/bun.lockb b/bun.lockb
index ddf5ae67..e3414a6e 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/components/message.tsx b/components/message.tsx
index 74c78fc7..173f3d43 100644
--- a/components/message.tsx
+++ b/components/message.tsx
@@ -2,6 +2,7 @@
import { StreamableValue, useStreamableValue } from 'ai/rsc'
import { MemoizedReactMarkdown } from './ui/markdown'
+import rehypeExternalLinks from 'rehype-external-links'
export function BotMessage({
content
@@ -14,7 +15,10 @@ export function BotMessage({
if (error) return <div>Error</div>
return (
- <MemoizedReactMarkdown className="prose-sm prose-neutral prose-a:text-accent-foreground/50">
+ <MemoizedReactMarkdown
+ rehypePlugins={[[rehypeExternalLinks, { target: '_blank' }]]}
+ className="prose-sm prose-neutral prose-a:text-accent-foreground/50"
+ >
{data}
</MemoizedReactMarkdown>
)
diff --git a/package.json b/package.json
index 54e7c45c..f2c25745 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
"react-dom": "^18",
"react-icons": "^5.0.1",
"react-markdown": "^9.0.1",
+ "rehype-external-links": "^3.0.0",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7"
},