Skip to content

Allow to open urls by pressing them #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/lwansbrough/react-native-markdown.git"
},
"version": "0.1.1",
"version": "0.1.2",
"description": "A component for rendering Markdown in React Native",
"main": "Markdown.js",
"author": "Lochlan Wansbrough <[email protected]> (http://lwansbrough.com)",
Expand Down
6 changes: 5 additions & 1 deletion rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var {
Image,
Text,
View,
Linking
} = React;
var SimpleMarkdown = require('simple-markdown');
var _ = require('lodash');
Expand Down Expand Up @@ -100,7 +101,10 @@ module.exports = function(styles) {
state.withinText = true;
return React.createElement(Text, {
key: state.key,
style: styles.autolink
style: styles.autolink,
onPress: function () {
Linking.openURL(node.content[0].content);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is grabbing the output text (what's in content). The link node should have a target element, and I'd recommend the following here:

Linking.openURL(SimpleMarkdown.sanitizeUrl(node.target));

which is based on https://github.com/Khan/simple-markdown/blob/master/simple-markdown.js#L1071

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it also may or may not be worth catching the error callback for Linking.openURL; I haven't used that to know how often it happens.)

It might also be useful to check for // links and change them to https:// links, as I'm not sure Linking.openURL can handle them.

}
}, output(node.content, state));
}
},
Expand Down