Skip to content

Commit

Permalink
autolink urls in response
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Mar 20, 2011
1 parent 55f33a7 commit 305adb2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/helpers/sinatra.rb
Expand Up @@ -11,8 +11,9 @@ def json(hash = {})

# colorize :js => '{ "blah": true }'
def colorize(hash = {})
tokens = CodeRay.scan(hash.values.first, hash.keys.first)
tokens.html.div.sub('CodeRay', 'highlight')
tokens = CodeRay.scan(hash.values.first, hash.keys.first)
colored = tokens.html.div.sub('CodeRay', 'highlight')
colored.gsub(/(https?:\/\/[^< "']+)/, '<a href="\1" target="_blank">\1</a>')
end
end
end
Expand Down

0 comments on commit 305adb2

Please sign in to comment.