Created
April 21, 2011 10:57
-
-
Save jed/934159 to your computer and use it in GitHub Desktop.
turning a tweet into html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function htmlify( tweet ) { | |
return tweet.replace( | |
/[@]+([A-Za-z0-9-_]+)|[#]+([A-Za-z0-9-_]+)|(\b(?:https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, | |
function( match, user, tag, url ) { | |
return 0, | |
user ? "@" + user.link( "http://twitter.com/" + user ) : | |
tag ? "#" + tag.link( "http://search.twitter.com/search?q=%23" + tag ) : | |
url ? url.split( "//" )[ 1 ].link( url ) : "" | |
}) | |
} |
(oh, this assumes a gsub implementation like in Prototype)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fwiw, I found this in an old project of mine: