Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
a simple jQuery plugin to add links to the text of tweets
// Twlinkify
// an absurdly simple jQuery plugin to linkify the text of tweets
;(function($) {
// from
function addTwitterLinks(text) {
var e = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
text = text.replace(e, "<a href='$1' target='_blank'>$1</a>");
e = /(^|\s)#(\w+)/g;
text = text.replace(e, "$1<a href='$2' target='_blank'>#$2</a>");
e = /(^|\s)@(\w+)/g;
text = text.replace(e, "$1<a href='$2' target='_blank'>@$2</a>");
return text;
$.fn.twlinkify = function() {
return this.each(function() {
var $el = $(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.