Skip to content

Instantly share code, notes, and snippets.

@sporkd
Created December 8, 2009 22:58
Show Gist options
  • Save sporkd/252078 to your computer and use it in GitHub Desktop.
Save sporkd/252078 to your computer and use it in GitHub Desktop.
require 'htmlentities'
class String
def plain_text
coder = HTMLEntities.new
coder.decode(self).gsub(/<\/?[^>]*>/, '')
end
def html
coder = HTMLEntities.new
self.gsub(/[^&><]/) { |match| coder.encode(match, :named) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment