Sha256: f75506124e58a12cd863975565a3cd94f43be02f4dc3a5495c4a32f9289a763f

Contents?: true

Size: 1015 Bytes

Versions: 25

Compression:

Stored size: 1015 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

25 entries across 23 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/loofah-2.15.0/lib/loofah/html/document_fragment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/loofah-2.18.0/lib/loofah/html/document_fragment.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/loofah-2.15.0/lib/loofah/html/document_fragment.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/loofah-2.18.0/lib/loofah/html/document_fragment.rb
loofah-2.20.0 lib/loofah/html/document_fragment.rb
loofah-2.19.1 lib/loofah/html/document_fragment.rb
loofah-2.19.0 lib/loofah/html/document_fragment.rb
loofah-2.18.0 lib/loofah/html/document_fragment.rb
loofah-2.17.0 lib/loofah/html/document_fragment.rb
loofah-2.16.0 lib/loofah/html/document_fragment.rb
loofah-2.15.0 lib/loofah/html/document_fragment.rb
loofah-2.14.0 lib/loofah/html/document_fragment.rb
loofah-2.13.0 lib/loofah/html/document_fragment.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/loofah-2.12.0/lib/loofah/html/document_fragment.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/loofah-2.12.0/lib/loofah/html/document_fragment.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/loofah-2.10.0/lib/loofah/html/document_fragment.rb
loofah-2.12.0 lib/loofah/html/document_fragment.rb
loofah-2.11.0 lib/loofah/html/document_fragment.rb
loofah-2.10.0 lib/loofah/html/document_fragment.rb
loofah-2.9.1 lib/loofah/html/document_fragment.rb