-
Notifications
You must be signed in to change notification settings - Fork 106
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
How to convert twitter @mentions? #10
Comments
react-linkify depends on linkify-it, which provides an example for handling twitter mentions: linkify.add('@', {
validate: function (text, pos, self) {
var tail = text.slice(pos);
if (!self.re.twitter) {
self.re.twitter = new RegExp(
'^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + self.re.src_ZPCc + ')'
);
}
if (self.re.twitter.test(tail)) {
// Linkifier allows punctuation chars before prefix,
// but we additionally disable `@` ("@@mention" is invalid)
if (pos >= 2 && tail[pos - 2] === '@') {
return false;
}
return tail.match(self.re.twitter)[0].length;
}
return 0;
},
normalize: function (match) {
match.url = 'https://twitter.com/' + match.url.replace(/^@/, '');
}
}); You can fork react-linkify and add the code above to line 7 in Linkify.jsx |
You can probably add a prop to Feel free to submit a PR. |
Would be easiest if this module exported its linkify instance, then you could do something like:
Of course doing it on the prop would be more idiomatic to react |
I agree with the "exposing the linkify instance" approach... I've handled it on #28 |
Any chance of getting that commit pushed as a new NPM version? 👍 |
@timothyallan - do you mean #20? I'm planning to get related parts cleaned up for #24 very soon. |
Sorry for the delay. There's a new release to support this now! |
I have text:
This is some twitter text by @raja @rao bla bla
I need to convert @raja and @rao as @raja and @rao
Thanks!
The text was updated successfully, but these errors were encountered: