2021-04-14 23:56:29 +00:00
|
|
|
|
import styles from './text.module.css'
|
2021-06-27 22:28:30 +00:00
|
|
|
|
import ReactMarkdown from 'react-markdown'
|
|
|
|
|
import gfm from 'remark-gfm'
|
|
|
|
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
|
|
|
|
|
/* Use `…/dist/cjs/…` if you’re not in ESM! */
|
|
|
|
|
import { atomDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'
|
2021-07-15 19:56:23 +00:00
|
|
|
|
import mention from '../lib/remark-mention'
|
2021-04-14 23:56:29 +00:00
|
|
|
|
|
|
|
|
|
export default function Text ({ children }) {
|
|
|
|
|
return (
|
2021-06-27 22:28:30 +00:00
|
|
|
|
<div className={styles.text}>
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
components={{
|
|
|
|
|
h1: 'h6',
|
|
|
|
|
h2: 'h6',
|
|
|
|
|
h3: 'h6',
|
|
|
|
|
h4: 'h6',
|
|
|
|
|
h5: 'h6',
|
|
|
|
|
h6: 'h6',
|
|
|
|
|
table: ({ node, ...props }) =>
|
|
|
|
|
<div className='table-responsive'>
|
|
|
|
|
<table className='table table-bordered table-sm' {...props} />
|
|
|
|
|
</div>,
|
|
|
|
|
code ({ node, inline, className, children, ...props }) {
|
|
|
|
|
const match = /language-(\w+)/.exec(className || '')
|
|
|
|
|
return !inline
|
|
|
|
|
? (
|
|
|
|
|
<SyntaxHighlighter showLineNumbers style={atomDark} language={match && match[1]} PreTag='div' {...props}>
|
|
|
|
|
{String(children).replace(/\n$/, '')}
|
|
|
|
|
</SyntaxHighlighter>
|
|
|
|
|
)
|
|
|
|
|
: (
|
|
|
|
|
<code className={className} style={atomDark} {...props}>
|
|
|
|
|
{children}
|
|
|
|
|
</code>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}}
|
2021-07-15 19:56:23 +00:00
|
|
|
|
remarkPlugins={[gfm, mention]}
|
2021-06-27 22:28:30 +00:00
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
</div>
|
2021-04-14 23:56:29 +00:00
|
|
|
|
)
|
|
|
|
|
}
|