fixed the formatTweet to create links to urls.
--- 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
--- a/unittests/tests/utils.js Mon Nov 21 15:45:47 2011 +0100
+++ b/unittests/tests/utils.js Mon Nov 21 16:20:16 2011 +0100
@@ -39,8 +39,8 @@
});
test("test function to format a tweet", function() {
- var input = "@handle #hashtag ";
- var output = "<a href='http://twitter.com/handle'>@handle</a> <a href='http://twitter.com/search?q=%23hashtag'>#hashtag</a> ";
+ var input = "@handle @bundle #hashtag http://t.co/11111";
+ var output = "<a href='http://twitter.com/handle'>@handle</a> <a href='http://twitter.com/bundle'>@bundle</a> <a href='http://twitter.com/search?q=%23hashtag'>#hashtag</a> <a href='http://t.co/11111'>http://t.co/11111</a>";
equal(IriSP.formatTweet(input), output, "the correct output is given");
});
}
\ No newline at end of file