Class: Loofah::HTML::DocumentFragment
- Inherits:
-
Nokogiri::HTML::DocumentFragment
- Object
- Nokogiri::HTML::DocumentFragment
- Loofah::HTML::DocumentFragment
- 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
-
.parse(tags, encoding = nil) ⇒ Object
Overridden Nokogiri::HTML::DocumentFragment constructor.
Instance Method Summary collapse
- #serialize_root ⇒ Object
-
#to_s ⇒ Object
(also: #serialize)
Returns the HTML markup contained by the fragment.
Methods included from TextBehavior
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 , encoding = nil doc = Loofah::HTML::Document.new encoding ||= .respond_to?(:encoding) ? .encoding.name : 'UTF-8' doc.encoding = encoding new(doc, ) end |
Instance Method Details
#serialize_root ⇒ Object
36 37 38 |
# File 'lib/loofah/html/document_fragment.rb', line 36 def serialize_root at_xpath("./body") || self end |
#to_s ⇒ Object 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 |