Class: Loofah::HTML::DocumentFragment

Inherits:
Nokogiri::HTML::DocumentFragment
  • Object
show all
Includes:
TextBehavior
Defined in:
lib/loofah/html/document_fragment.rb

Overview

Subclass of Nokogiri::HTML::DocumentFragment.

See Loofah::ScrubBehavior and Loofah::TextBehavior for additional methods.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TextBehavior

#text, #to_text

Class Method Details

.parse(tags, encoding = nil) ⇒ Object

Overridden Nokogiri::HTML::DocumentFragment

constructor. Applications should use Loofah.fragment to
parse a fragment.


18
19
20
21
22
23
24
25
# File 'lib/loofah/html/document_fragment.rb', line 18

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

Instance Method Details

#serialize_rootObject



36
37
38
# File 'lib/loofah/html/document_fragment.rb', line 36

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

#to_sObject Also known as: serialize

Returns the HTML markup contained by the fragment



31
32
33
# File 'lib/loofah/html/document_fragment.rb', line 31

def to_s
  serialize_root.children.to_s
end