/ Published in: JavaScript
This is 3 lines of javascript code to tweetify plain text returned by Twitter API
Input : RT @TTintheCloud: How much are free #cloudcomputing trial offers from Google, Amazon and Microsoft actually WORTH? http://bit.ly/i4w4qa
Output : RT <a href="http://twitter.com/TTintheCloud">@TTintheCloud</a>: How much are free <a href="http://search.twitter.com/search?q=&tag=cloudcomputing&lang=all">#cloudcomputing</a> trial offers from Google, Amazon and Microsoft actually WORTH? <a href="http://bit.ly/i4w4qa">http://bit.ly/i4w4qa</a>
Input : RT @TTintheCloud: How much are free #cloudcomputing trial offers from Google, Amazon and Microsoft actually WORTH? http://bit.ly/i4w4qa
Output : RT <a href="http://twitter.com/TTintheCloud">@TTintheCloud</a>: How much are free <a href="http://search.twitter.com/search?q=&tag=cloudcomputing&lang=all">#cloudcomputing</a> trial offers from Google, Amazon and Microsoft actually WORTH? <a href="http://bit.ly/i4w4qa">http://bit.ly/i4w4qa</a>
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function tweetify(text) { text = text.replace(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:(?:[^\s()<>.]+[.]?)+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?���«���»�¢ï¿½ï¿½�¢ï¿½ï¿½�¢ï¿½ï¿½�¢ï¿½ï¿½]))/gi, "<a target=_blank href=$1>$1</a>"); text = text.replace(/[\@]+([A-Za-z0-9-_]+)/gi, "<a target=_blank href=http://twitter.com/$1>@$1</a>"); return text.replace(/(?:^| )[\#]+([A-Za-z0-9-_]+)/gi, " <a target=_blank href=http://search.twitter.com/search?q=&tag=$1&lang=all>#$1</a>"); }