nokogiri / 1.13.0 / nokogiri / html5 / documentfragment.html /

class Nokogiri::HTML5::DocumentFragment

Parent:
Nokogiri::HTML4::DocumentFragment

Since v1.12.0

💡 HTML5 functionality is not available when running JRuby.

Attributes

document [RW]
errors [RW]

Public Class Methods

new (doc, tags = nil, ctx = nil, options = {}) Show source
# File lib/nokogiri/html5/document_fragment.rb, line 32
def initialize(doc, tags = nil, ctx = nil, options = {})
  self.document = doc
  self.errors = []
  return self unless tags

  max_attributes = options[:max_attributes] || Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES
  max_errors = options[:max_errors] || Nokogiri::Gumbo::DEFAULT_MAX_ERRORS
  max_depth = options[:max_tree_depth] || Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH
  tags = Nokogiri::HTML5.read_and_encode(tags, nil)
  Nokogiri::Gumbo.fragment(self, tags, ctx, max_attributes, max_errors, max_depth)
end

Create a document fragment.

parse (tags, encoding = nil, options = {}) Show source
# File lib/nokogiri/html5/document_fragment.rb, line 51
def self.parse(tags, encoding = nil, options = {})
  doc = HTML5::Document.new
  tags = HTML5.read_and_encode(tags, encoding)
  doc.encoding = "UTF-8"
  new(doc, tags, nil, options)
end

Parse a document fragment from tags, returning a Nodeset.

Public Instance Methods

serialize (options = {}, &block) Show source
# File lib/nokogiri/html5/document_fragment.rb, line 44
def serialize(options = {}, &block)
  # Bypass XML::Document.serialize which doesn't support options even
  # though XML::Node.serialize does!
  XML::Node.instance_method(:serialize).bind(self).call(options, &block)
end

© 2008–2018 Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo,
Patrick Mahoney, Yoko Harada, Akinori MUSHA, John Shahid, Lars Kanis
Licensed under the MIT License.
https://nokogiri.org/rdoc/Nokogiri/HTML5/DocumentFragment.html