Sha256: 0cff724507bafdb66f1e5a4bc0c375d8975405de743986a339711b3309a15914

Contents?: true

Size: 1013 Bytes

Versions: 4

Compression:

Stored size: 1013 Bytes

Contents

# frozen_string_literal: true
module Loofah
  module HTML # :nodoc:
    #
    #  Subclass of Nokogiri::HTML::DocumentFragment.
    #
    #  See Loofah::ScrubBehavior and Loofah::TextBehavior for additional methods.
    #
    class DocumentFragment < Nokogiri::HTML::DocumentFragment
      include Loofah::TextBehavior

      class << self
        #
        #  Overridden Nokogiri::HTML::DocumentFragment
        #  constructor. Applications should use Loofah.fragment to
        #  parse a fragment.
        #
        def parse tags, encoding = nil
          doc = Loofah::HTML::Document.new

          encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : 'UTF-8'
          doc.encoding = encoding

          new(doc, tags)
        end
      end

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

      def serialize_root
        at_xpath("./body") || self
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 4 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/loofah-2.4.0/lib/loofah/html/document_fragment.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/loofah-2.4.0/lib/loofah/html/document_fragment.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/loofah-2.4.0/lib/loofah/html/document_fragment.rb
loofah-2.4.0 lib/loofah/html/document_fragment.rb