Skip to content

Instantly share code, notes, and snippets.

@hernan
Forked from jed/LICENSE.txt
Created November 2, 2011 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hernan/1333568 to your computer and use it in GitHub Desktop.
Save hernan/1333568 to your computer and use it in GitHub Desktop.
linkify @mentions and #hashtags in a tweet
function(
a // the text of the tweet to be enlinked
){
return a.replace( // replace
/\b[@#]\w+/g, // any mention/hashtag
function(
b, // the matched mention/hashtag
c // placeholder
){
c = "twitter.com/"; // the core twitter url
return b.link( // put the match in a link to
"//" + ( // the "//" protocol, +
b[a = "search"] // match the url, reusing for "search"
("#") // if the match starts with "#"
? c // twitter.com/, or otherwise
: a + "." + c + // search.twitter.com/ +
a + "?q=" // search?q=
) + // and then finally, +
b // the mention/hashtag.
)
}
)
}
function(a){return a.replace(/\b[@#]\w+/g,function(b,c){c="twitter.com/";return b.link("//"+(b[a="search"]("#")?c:a+"."+c+a+"?q=")+b)})}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "enlink",
"keywords": ["twitter", "tweet", "link", "mention", "hashtag"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment