module Loofah::Helpers

def remove_extraneous_whitespace(string)


TODO: remove this in a future major-point-release.

A helper to remove extraneous whitespace from text-ified HTML.
def remove_extraneous_whitespace(string)
  Loofah.remove_extraneous_whitespace(string)
end

def sanitize(string_or_io)


# => "<script src=\"http://ha.ckers.org/xss.js\"></script>"
Loofah::Helpers.sanitize("")

A replacement for Rails's built-in +sanitize+ helper.
def sanitize(string_or_io)
  loofah_fragment = Loofah.html4_fragment(string_or_io)
  loofah_fragment.scrub!(:strip)
  loofah_fragment.xpath("./form").each(&:remove)
  loofah_fragment.to_s
end

def sanitize_css(style_string)


# => "display: block;"
Loofah::Helpers.sanitize_css("display:block;background-image:url(http://example.com/foo.jpg)")

A replacement for Rails's built-in +sanitize_css+ helper.
def sanitize_css(style_string)
  ::Loofah::HTML5::Scrub.scrub_css(style_string)
end

def strip_tags(string_or_io)


Loofah::Helpers.strip_tags("
Hello there
") # => "Hello there"

A replacement for Rails's built-in +strip_tags+ helper.
def strip_tags(string_or_io)
  Loofah.html4_fragment(string_or_io).text
end