Skip to content

Instantly share code, notes, and snippets.

@jed
Created April 21, 2011 10:57
Show Gist options
  • Save jed/934159 to your computer and use it in GitHub Desktop.
Save jed/934159 to your computer and use it in GitHub Desktop.
turning a tweet into html
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 ) : ""
})
}
@madrobby
Copy link

madrobby commented Aug 6, 2011

(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