forked from mientjan/react-native-markdown-renderer
-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathparser.js
27 lines (23 loc) · 759 Bytes
/
parser.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
import tokensToAST from './util/tokensToAST';
import {stringToTokens} from './util/stringToTokens';
import {cleanupTokens} from './util/cleanupTokens';
import groupTextTokens from './util/groupTextTokens';
import omitListItemParagraph from './util/omitListItemParagraph';
/**
*
* @param {string} source
* @param {function} [renderer]
* @param {AstRenderer} [markdownIt]
* @return {View}
*/
export default function parser(source, renderer, markdownIt) {
if (Array.isArray(source)) {
return renderer(source);
}
let tokens = stringToTokens(source, markdownIt);
tokens = cleanupTokens(tokens);
tokens = groupTextTokens(tokens);
tokens = omitListItemParagraph(tokens);
const astTree = tokensToAST(tokens);
return renderer(astTree);
}