Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type Props = {
children?: string,
rules: Object,
whitelist: Array,
blacklist: Array
blacklist: Array,
onLinkPress: Function
}

type DefaultProps = Props & {
Expand Down Expand Up @@ -49,7 +50,7 @@ class Markdown extends Component<DefaultProps, Props, void> {
_.merge(
{},
SimpleMarkdown.defaultRules,
initialRules(mergedStyles),
initialRules(mergedStyles, this.props),
this.props.rules
)
)
Expand Down
6 changes: 4 additions & 2 deletions rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
},
Expand Down