gregjacobs / Autolinker.js

Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
MIT License
1.48k stars 238 forks source link

Add support for usernames across more social networks #119

Open jmillerdesign opened 9 years ago

jmillerdesign commented 9 years ago

Could this either be added to the core, or could you explain how I could pass options to Autolinker.js to allow for this? It's limiting usernames to 15 characters, but other networks support longer usernames.

Twitter: 15 Instagram: 30 Facebook: 50 Tumblr: 32

gregjacobs commented 8 years ago

Hey, sorry for the late response here.

Currently Autolinker only has built-in support for Twitter and there's really no way to override it, but I like the idea of a username option and specifying which service it should link to. Will work on this.

simison commented 8 years ago

I feel like Twitter username should be something generic rather than tight to one service. It could default to twitter, but user should be able to defined the URL and syntax easily.

For this it would make sense to rename twitter thing to something else, so it would be a breaking change.

My usercase would be to use it with my own site's usernames, actually.

gregjacobs commented 8 years ago

Definitely agree, and interesting point too for your own website. I think we can maintain backward compatibility though for the options, where the newer username option would just override the twitter option if both are provided.

Any ideas on how you might like the options laid out for this? My initial thought is something like this:

Autolinker.link( text, {
    username : 'twitter'  // or 'facebook', 'instagram', 'tumblr', etc.
} );

And then for the use case of your own website, you can always use the replaceFn, but feeling like it should be a bit easier if possible. Maybe something like this:

Autolinker.link( text, {
    username : { 
        type: 'custom', 
        template: 'http://my.website.com/{username}' 
    }
} );

Thoughts?

simison commented 8 years ago

Yeah and I feel like passing regexp as an option should be possible as well, since someone might want to support _-. and capital letters and some just lowercase a-z.

Oh and sometimes you might want to recognise capital letters but have them lowercase at the URL.

devonzara commented 8 years ago

Personally, I'd prefer the term 'mention' rather than 'username', but that would break backwards compatibility unless made as an alias. Secondly, I'd probably use service rather than type.

I agree that there should be an optional regex option and a way to set the prefixing character/regex, seeing as services such as Google+ use a + instead of an @ symbol.

eg.

Autolinker.link( text, {
    mention: { 
        service: 'custom', // twitter (default), facebook, instagram, tumblr, google
        regex: '[A-Z][a-zA-Z0-9]{2, 13}',
        prefix: '+',
        template: 'http://my.website.com/{username}' // 
    }
} );
simison commented 8 years ago

+1 @devonzara; good thinking!

ReedD commented 8 years ago

:+1: Any word on this?

antondomratchev commented 8 years ago

Resurecting in 3...2...1 @devonzara Do you have any work done for your suggestion, I would like to get an implementation of this into a PR but wanted to double check if you had any work in progress.

jmillerdesign commented 8 years ago

I'd be willing to help out on a PR if we can agree on a syntax.

gregjacobs commented 8 years ago

blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; } Hey, yes, so sorry, I'm so crazy busy these days. What are your thoughts on that?

Sent from Yahoo Mail for iPhone

On Monday, June 13, 2016, 12:30 PM, J. Miller notifications@github.com wrote:

I'd be willing to help out on a PR if we can agree on a syntax.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

olafleur commented 7 years ago

@jmillerdesign : as of today, we have, mentions for Twitter and Instagram.

With the current structure, I guess it would be relatively easy to add Facebook and Tumblr if this is still wanted.