Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
def add_url_markup(text)
urls = []
users =[]
# find urls
text.split.each{|a| a=~/(http\:\/\/\S+)/; urls << $1}
# find twitter usernames (@someusername)
text.split.each{|a| a=~/(\@\S+)/; users << $1}
# add markup
users.compact.each{|user| text.gsub!(user, "<a href='{user.gsub('@','')}'>#{user}</a>")}
urls.compact.each{|url| text.gsub!(url, "<a href='#{url}'>#{url}</a>")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment