Skip to content

Instantly share code, notes, and snippets.

@atnan
Created July 17, 2009 04:50
Show Gist options
  • Save atnan/148891 to your computer and use it in GitHub Desktop.
Save atnan/148891 to your computer and use it in GitHub Desktop.
var ify = function() {
return {
"link": function(t) {
return t.replace(/(^|\s+)(https*\:\/\/\S+)/g, function(m, m1, link) {
return m1.concat('<a href="', link, '">', link.substr(0, 24), 25 < link.length ? '...' : '', '</a>');
});
},
"at": function(t) {
return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, ‘$1@<a href=”http://twitter.com/$2″>$2</a>’);
},
“hash”: function(t) {
return t.replace(/(^|\s+)\#([a-zA-Z0-9_]+)/g, ‘$1#<a href=”http://search.twitter.com/search?q=%23$2″>$2</a>’);
},
clean: function(tweet) {
return this.hash(this.at(this.link(tweet)));
}
};
}();
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