juiceo / react-native-easy-markdown

Simple & customizable React Native component to render Github-flavoured markdown using minimal native components.
https://www.npmjs.com/package/react-native-easy-markdown
65 stars 62 forks source link

Custom and code rules #13

Open diegolmello opened 6 years ago

diegolmello commented 6 years ago

Custom rules allow to send components to react-native-easy-markdown. A Twitter's username rule could be created like this:

<Markdown rules={{
    username: {
        order: 1,
        match: SimpleMarkdown.inlineRegex(/@[0-9a-zA-Z-_.]+/),
        parse: capture => ({ content: capture[0] }),
        react: (node, output, state) => ({
            type: 'custom',
            key: state.key,
            props: {
                children: (
                    <Text
                        key={state.key}
                        style={{ color: 'blue', fontWeight: 'bold' }}
                        onPress={() => alert('Works')}
                    >
                        {node.content}
                    </Text>
                )
            }
        })
    }
}}>