src/js/utils.js
branchpopcorn-port
changeset 297 ed4a459c9290
parent 285 b7aa28af2c10
child 308 495ef0f3e483
--- a/src/js/utils.js	Mon Nov 21 15:45:47 2011 +0100
+++ b/src/js/utils.js	Mon Nov 21 16:20:16 2011 +0100
@@ -51,12 +51,15 @@
 
 /* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */
 IriSP.formatTweet = function(tweet) {
-  var rNickname = /@(\w+)/; // matches a @handle
-  var rHashtag = /#(\w+)/;  // matches a hashtag
-  var i1 = tweet.replace(rNickname, "<a href='http://twitter.com/$1'>@$1</a>");
-  var i2 = i1.replace(rHashtag, "<a href='http://twitter.com/search?q=%23$1'>#$1</a>");
+  var rNickname = /@(\w+)/gi; // matches a @handle
+  var rHashtag = /#(\w+)/gi;  // matches a hashtag
+  var rUrl = /((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi; // copied from http://codegolf.stackexchange.com/questions/464/shortest-url-regex-match-in-javascript/480#480
   
-  return i2;
+  var i1 = tweet.replace(rUrl, "<a href='$1'>$1</a>");
+  var i2 = i1.replace(rNickname, "<a href='http://twitter.com/$1'>@$1</a>");
+  var i3 = i2.replace(rHashtag, "<a href='http://twitter.com/search?q=%23$1'>#$1</a>");
+
+  return i3;
 };
 
 /* for ie compatibility