Darshan Thakare Aksel Joonas Reedi commited on
feat: add support to open links in new tab (#76)
Browse filesCo-authored-by: Aksel Joonas Reedi <125026660+akseljoonas@users.noreply.github.com>
frontend/src/components/Chat/MarkdownContent.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { useMemo, useRef, useState, useEffect } from 'react';
|
| 2 |
import { Box } from '@mui/material';
|
| 3 |
import ReactMarkdown from 'react-markdown';
|
| 4 |
import remarkGfm from 'remark-gfm';
|
|
@@ -166,9 +166,17 @@ export default function MarkdownContent({ content, sx, isStreaming = false }: Ma
|
|
| 166 |
|
| 167 |
const remarkPlugins = useMemo(() => [remarkGfm], []);
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
return (
|
| 170 |
<Box sx={[markdownSx, ...(Array.isArray(sx) ? sx : sx ? [sx] : [])]}>
|
| 171 |
-
<ReactMarkdown remarkPlugins={remarkPlugins}>{displayContent}</ReactMarkdown>
|
| 172 |
</Box>
|
| 173 |
);
|
| 174 |
}
|
|
|
|
| 1 |
+
import { useMemo, useRef, useState, useEffect, type ComponentPropsWithoutRef } from 'react';
|
| 2 |
import { Box } from '@mui/material';
|
| 3 |
import ReactMarkdown from 'react-markdown';
|
| 4 |
import remarkGfm from 'remark-gfm';
|
|
|
|
| 166 |
|
| 167 |
const remarkPlugins = useMemo(() => [remarkGfm], []);
|
| 168 |
|
| 169 |
+
const components = useMemo(() => ({
|
| 170 |
+
a: ({ href, children, ...props }: ComponentPropsWithoutRef<'a'>) => (
|
| 171 |
+
<a href={href} target="_blank" rel="noopener noreferrer" {...props}>
|
| 172 |
+
{children}
|
| 173 |
+
</a>
|
| 174 |
+
),
|
| 175 |
+
}), []);
|
| 176 |
+
|
| 177 |
return (
|
| 178 |
<Box sx={[markdownSx, ...(Array.isArray(sx) ? sx : sx ? [sx] : [])]}>
|
| 179 |
+
<ReactMarkdown remarkPlugins={remarkPlugins} components={components}>{displayContent}</ReactMarkdown>
|
| 180 |
</Box>
|
| 181 |
);
|
| 182 |
}
|