Skip to content
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

Closed
rajaraodv opened this issue Oct 28, 2015 · 8 comments
Closed

How to convert twitter @mentions? #10

rajaraodv opened this issue Oct 28, 2015 · 8 comments

Comments

@rajaraodv
Copy link

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!

@Nurymka
Copy link

Nurymka commented Feb 18, 2016

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

@tasti
Copy link
Owner

tasti commented Feb 20, 2016

You can probably add a prop to Linkify that takes a set of rules that follows the (schema, definition) format from https://github.com/markdown-it/linkify-it#addschema-definition. Then in the constructor, call linkify.add(...).

Feel free to submit a PR.

@yocontra
Copy link

Would be easiest if this module exported its linkify instance, then you could do something like:

thisModule.linkify.add('@', contentsOfPreviousComment)

Of course doing it on the prop would be more idiomatic to react

@ivanalejandro0
Copy link
Contributor

I agree with the "exposing the linkify instance" approach... I've handled it on #28

@timothyallan
Copy link

Any chance of getting that commit pushed as a new NPM version? 👍

@tasti
Copy link
Owner

tasti commented Feb 1, 2017

@timothyallan - do you mean #20? I'm planning to get related parts cleaned up for #24 very soon.

@timothyallan
Copy link

@tasti nope, #28 The latest NPM release says that's the only commit that's missing!

@tasti
Copy link
Owner

tasti commented Feb 9, 2017

Sorry for the delay. There's a new release to support this now!

@tasti tasti closed this as completed Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants