Skip to content

Instantly share code, notes, and snippets.

Embed
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='http://twitter.com/#{user.gsub('@','')}'>#{user}</a>")}
urls.compact.each{|url| text.gsub!(url, "<a href='#{url}'>#{url}</a>")}
text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment