39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import ReactMarkdown from 'react-markdown';
|
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
|
import remarkEmoji from 'remark-emoji';
|
|
import remarkGfm from 'remark-gfm';
|
|
import './MarkdownContent.css';
|
|
|
|
export default function PostContent({ content }: { content: string }) {
|
|
return (
|
|
<div className="markdown-content">
|
|
<ReactMarkdown
|
|
remarkPlugins={[remarkGfm, remarkEmoji]}
|
|
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>
|
|
);
|
|
}
|