2024-01-05 09:18:34 +01:00
|
|
|
import { Link } from '@mui/material';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { AnchorHTMLAttributes, ComponentProps } from 'react';
|
2024-01-05 09:18:34 +01:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
|
|
|
|
const LinkRenderer = ({
|
|
|
|
href = '',
|
|
|
|
children,
|
|
|
|
}: AnchorHTMLAttributes<HTMLAnchorElement>) => {
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
if (href.startsWith('/'))
|
|
|
|
return <Link onClick={() => navigate(href)}>{children}</Link>;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Link href={href} target='_blank' rel='noreferrer'>
|
|
|
|
{children}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-09-26 15:48:52 +02:00
|
|
|
export const Markdown = ({
|
|
|
|
components,
|
|
|
|
...props
|
|
|
|
}: ComponentProps<typeof ReactMarkdown>) => (
|
|
|
|
<ReactMarkdown components={{ a: LinkRenderer, ...components }} {...props} />
|
2024-01-05 09:18:34 +01:00
|
|
|
);
|