chore: markdown

This commit is contained in:
lencx
2023-01-16 21:00:56 +08:00
parent fb88ba8a1f
commit f822a56993
3 changed files with 54 additions and 25 deletions

7
src/components/Markdown/index.scss vendored Normal file
View File

@@ -0,0 +1,7 @@
.markdown-body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
pre, code {
font-family: monospace, monospace;
}
}

44
src/components/Markdown/index.tsx vendored Normal file
View File

@@ -0,0 +1,44 @@
import { FC } from 'react';
import ReactMarkdown from 'react-markdown';
import SyntaxHighlighter from 'react-syntax-highlighter';
import agate from 'react-syntax-highlighter/dist/esm/styles/hljs/agate';
import './index.scss';
interface MarkdownProps {
children: string;
}
const Markdown: FC<MarkdownProps> = ({ children }) => {
return (
<div className='markdown-body'>
<ReactMarkdown
children={children}
linkTarget="_blank"
components={{
code({node, inline, className, children, ...props}) {
const match = /language-(\w+)/.exec(className || '')
return !inline && match ? (
<SyntaxHighlighter
children={String(children).replace(/\n$/, '')}
style={agate as any}
language={match[1]}
showLineNumbers
lineNumberStyle={{ color: '#999' }}
PreTag="div"
{...props}
/>
) : (
<code className={className} {...props}>
{children}
</code>
)
}
}}
/>
</div>
)
}
export default Markdown;