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.


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

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



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

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

#to_sObject Also known as: serialize

Returns the HTML markup contained by the fragment



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

def to_s
  serialize_root.children.to_s
end