2023-09-10 20:19:31 -05:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
|
|
|
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
|
|
|
import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
2023-09-11 21:35:12 -05:00
|
|
|
import remarkEmoji from 'remark-emoji';
|
2023-09-10 20:19:31 -05:00
|
|
|
import remarkGfm from 'remark-gfm';
|
|
|
|
|
import './MarkdownContent.css';
|
|
|
|
|
|
|
|
|
|
export default function PostContent({ content }: { content: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className='markdown-content'>
|
|
|
|
|
<ReactMarkdown
|
2023-09-11 21:35:12 -05:00
|
|
|
remarkPlugins={[remarkGfm, remarkEmoji]}
|
2023-09-10 20:19:31 -05:00
|
|
|
components={{
|
|
|
|
|
code({ node, inline, className, children, ...props }) {
|
|
|
|
|
const match = /language-(\w+)/.exec(className || '');
|
|
|
|
|
|
|
|
|
|
return !inline && match ? (
|
|
|
|
|
<SyntaxHighlighter
|
|
|
|
|
{...props}
|
|
|
|
|
style={oneDark}
|
|
|
|
|
language={match[1]}
|
|
|
|
|
PreTag='div'
|
|
|
|
|
>
|
|
|
|
|
{String(children).replace(/\n$/, '')}
|
|
|
|
|
</SyntaxHighlighter>
|
|
|
|
|
) : (
|
|
|
|
|
<code
|
|
|
|
|
{...props}
|
|
|
|
|
className={className}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</code>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{content}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|