Skip to content

Instantly share code, notes, and snippets.

@domwom
Created June 5, 2009 11:27
Show Gist options
  • Save domwom/124240 to your computer and use it in GitHub Desktop.
Save domwom/124240 to your computer and use it in GitHub Desktop.
/*
* Twita@talinkahashifyer
* http://www.dustindiaz.com
* http://www.dustindiaz.com/basement/ify.html
*
* Copyright (c) 2009 Dustin Diaz
* licensed under public BSD
*/
var ify = function() {
return {
"link": function(t) {
return t.replace(/(^|\s+)(https*\:\/\/\S+[^\.\s+])/g, function(m, m1, link) {
return ((m1 != '') ? ' ' : '') + '<a href=' + link + '>' + ((link.length > 25) ? link.substr(0, 24) + '...' : link) + '</a>';
});
},
"at": function(t) {
return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, function(m, m1, m2) {
return ((m1 != '') ? ' ' : '') + '@<a href="http://twitter.com/' + m2 + '">' + m2 + '</a>';
});
},
"hash": function(t) {
return t.replace(/(^|\s+)\#([a-zA-Z0-9_]+)/g, function(m, m1, m2) {
return ((m1 != '') ? ' ' : '') + '#<a href="http://search.twitter.com/search?q=%23' + m2 + '">' + m2 + '</a>';
});
},
"clean": function(tweet) {
return this.hash(this.at(this.link(tweet)));
}
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment