stream/src/components/Markdown/index.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

/* eslint-disable jsx-a11y/anchor-has-content */
import { h, Fragment } from 'preact'
import MarkdownRenderer from 'markdown-to-jsx'
import { MarkdownWrapper } from './styles'
2021-10-11 17:15:09 +00:00
import { P, A, H1, H2, H3, Span } from '../Text'
const Markdown = ({ children, withLinebreaks, options, ...rest }) => (
<MarkdownWrapper $withLinebreaks={withLinebreaks}>
<MarkdownRenderer
options={{
overrides: {
p: {
component: P,
},
span: {
component: P,
},
em: {
component: ({ children: spanChildren }) => (
<Span fontStyle="italic">{spanChildren}</Span>
),
},
a: {
component: props => (
<A
data-hoverable
target="_blank"
rel="noopener noreferrer"
{...props}
/>
),
},
h1: {
component: H1,
},
h2: {
component: H2,
},
2021-10-11 17:15:09 +00:00
h3: {
component: H3,
},
},
...options,
}}
{...rest}
>
{children}
</MarkdownRenderer>
</MarkdownWrapper>
)
export default Markdown