Sha256: 3456e9ad3b01ca784ee31274cda05dd5bfc4e83e3eea60e62244c040eca718fd

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Loofah
  module HTML # :nodoc:
    #
    #  Subclass of Nokogiri::HTML::DocumentFragment.
    #
    #  See Loofah::ScrubBehavior for additional methods.
    #
    class DocumentFragment < Nokogiri::HTML::DocumentFragment
      class << self
        #
        #  Overridden Nokogiri::HTML::DocumentFragment
        #  constructor. Applications should use Loofah.fragment to
        #  parse a fragment.
        #
        def parse tags
          self.new(Loofah::HTML::Document.new, tags)
        end
      end

      #
      #  Returns the HTML markup contained by the fragment
      #
      def to_s
        serialize_roots.children.to_s
      end
      alias :serialize :to_s

      #
      #  Returns a plain-text version of the markup contained by the fragment
      #
      def text
        encode_special_chars serialize_roots.children.inner_text
      end
      alias :inner_text :text
      alias :to_str     :text

      private

      def serialize_roots # :nodoc:
        xpath("./body").first || self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
loofah-0.4.6 lib/loofah/html/document_fragment.rb
loofah-0.4.5 lib/loofah/html/document_fragment.rb