-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (58 loc) · 1.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { createElement } from 'react'
import marksy from 'marksy/jsx'
import Cui from 'react-cui'
import {
Paragraph,
Image,
Heading,
Code,
Pre,
ListItem,
CtaLink
} from './styled-components'
const MarkDown = ({ children, color }) => {
const renderers = {
p: props => {
return <Paragraph {...props} />
},
h1: props => {
return <Heading level={1} {...props} />
},
h2: props => {
return <Heading level={2} {...props} />
},
h3: props => {
return <Heading level={3} {...props} />
},
h4: props => {
return <Heading level={4} {...props} />
},
img: props => {
return <Image {...props} align={props.align} />
},
li: props => {
return <ListItem {...props} />
},
code: ({ language, code }) => {
if (language !== 'cta') {
return <Pre>{code}</Pre>
}
return <CtaLink value={code} />
},
codespan: props => {
return <Code {...props} />
}
}
const compile = marksy({
createElement,
elements: renderers,
components: {
Cui (props) {
return <Cui {...props} />
}
}
})
const compiled = compile(children)
return compiled.tree
}
export default MarkDown