Skip to content

Instantly share code, notes, and snippets.

@mretzak
Created August 7, 2009 17:16
Show Gist options
  • Save mretzak/164024 to your computer and use it in GitHub Desktop.
Save mretzak/164024 to your computer and use it in GitHub Desktop.
# This code will take the raw source text from a tweet and add appropriate links to #hastags, @ replies, and links. The ugly stuff in there is dealing with various formats of html character codes
def to_html
self.text.gsub("&amp;","&").gsub(/(http:\/\/([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?)/,'<a href="\1" target="_blank" rel="nofollow">\1</a>').gsub(/@(\w+)/,'@<a href="http://twitter.com/\1" target="_blank" rel="nofollow">\1</a>').gsub(/&#/,"~begonia~~").gsub(/#(\w+)/,' #<a href="http://twitter.com/#search?q=%23\1" target="_blank" rel="nofollow">\1</a>').gsub(/~begonia~~/,"&#")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment