Sha256: 23a371f1173d73469f9239a528398209887a0b3fbb7d252f98c6cc26a6086639

Contents?: true

Size: 868 Bytes

Versions: 4

Compression:

Stored size: 868 Bytes

Contents

module Loofah
  module Helpers
    class << self
      #
      #  A replacement for Rails's built-in +strip_tags+ helper.
      #
      #   Loofah::Helpers.strip_tags("<div>Hello <b>there</b></div>") # => "Hello there"
      #
      def strip_tags(string_or_io)
        Loofah.fragment(string_or_io).text
      end

      #
      #  A replacement for Rails's built-in +sanitize+ helper.
      #
      #   Loofah::Helpers.sanitize("<script src=http://ha.ckers.org/xss.js></script>") # => "&lt;script src=\"http://ha.ckers.org/xss.js\"&gt;&lt;/script&gt;"
      #
      def sanitize(string_or_io)
        Loofah.scrub_fragment(string_or_io, :strip).to_s
      end

      #
      #  A helper to remove extraneous whitespace from text-ified HTML
      #
      def remove_extraneous_whitespace(string)
        string.gsub(/\n\s*\n\s*\n/,"\n\n")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
loofah-1.1.0 lib/loofah/helpers.rb
loofah-1.0.0 lib/loofah/helpers.rb
loofah-1.0.0.beta.1 lib/loofah/helpers.rb
loofah-0.4.7 lib/loofah/helpers.rb