-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
47 lines (46 loc) · 1.03 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
import React from 'react';
import {
View,
ScrollView,
Text,
Image
} from 'react-native'
import CommonMark from 'commonmark';
import styles from './styles';
import ReactNativeRenderer from './commonmark-react-renderer';
export default class ReactNativeMarkdown extends React.Component {
render() {
let parser = new CommonMark.Parser();
let renderer = new ReactNativeRenderer({
skipHtml: true,
allowedTypes: [
'heading',
'text',
'paragraph',
'strong',
'emph',
'list',
'item',
'image',
'link',
'code_block',
'block_quote'
],
renderers: {
heading: View,
paragraph: Text,
text: Text,
strong: Text,
emph: Text,
list: View,
item: Text,
image: Image,
link: Text,
code_block: Text,
},
});
var ast = parser.parse(this.props.children || '');
var children = renderer.render(ast);
return <ScrollView>{children}</ScrollView>
}
}