Skip to content

Instantly share code, notes, and snippets.

@audionerd
Created April 7, 2009 19: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 audionerd/91401 to your computer and use it in GitHub Desktop.
Save audionerd/91401 to your computer and use it in GitHub Desktop.
/* via http://www.simonwhatley.co.uk/ */
Twitter = {
format: function(tweet) {
return Twitter.formatHashtag(Twitter.formatUsername(Twitter.formatURL(tweet)));
},
formatURL: function(string) {
return string.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(url) {
return url.link(url);
});
},
formatUsername: function(string) {
return string.replace(/[@]+[A-Za-z0-9-_]+/, function(u) {
var username = u.replace("@","");
return u.link("http://twitter.com/"+username);
});
},
formatHashtag: function(string) {
return string.replace(/[#]+[A-Za-z0-9-_]+/, function(t) {
var tag = t.replace("#","%23");
return t.link("http://search.twitter.com/search?q="+tag);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment