diff --git a/index.js b/index.js index 2ad9217..eea4439 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,8 @@ type Props = { children?: string, rules: Object, whitelist: Array, - blacklist: Array + blacklist: Array, + onLinkPress: Function } type DefaultProps = Props & { @@ -49,7 +50,7 @@ class Markdown extends Component { _.merge( {}, SimpleMarkdown.defaultRules, - initialRules(mergedStyles), + initialRules(mergedStyles, this.props), this.props.rules ) ) diff --git a/rules.js b/rules.js index 93eea49..b33e25f 100644 --- a/rules.js +++ b/rules.js @@ -3,7 +3,7 @@ import { Image, Text, View, Linking } from 'react-native' import SimpleMarkdown from 'simple-markdown' import _ from 'lodash' -export default (styles) => ({ +export default (styles, props) => ({ autolink: { react: (node, output, state) => { state.withinText = true @@ -105,10 +105,12 @@ export default (styles) => ({ const openUrl = (url) => { Linking.openURL(url).catch(error => console.warn('An error occurred: ', error)) } + const onPress = props.onLinkPress ? props.onLinkPress : openUrl + return createElement(Text, { style: node.target.match(/@/) ? styles.mailTo : styles.link, key: state.key, - onPress: () => openUrl(node.target) + onPress: () => onPress(node.target) }, output(node.content, state)) } },