class Nokogiri::HTML5::DocumentFragment
💡 HTML5 functionality is not available when running JRuby.
Since v1.12.0
def self.parse(tags, encoding = nil, options = {})
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
def extract_params(params) # :nodoc:
def extract_params(params) # :nodoc: handler = params.find do |param| ![Hash, String, Symbol].include?(param.class) end params -= [handler] if handler hashes = [] while Hash === params.last || params.last.nil? hashes << params.pop break if params.empty? end ns, binds = hashes.reverse ns ||= begin ns = {} children.each { |child| ns.merge!(child.namespaces) } ns end [params, handler, ns, binds] end
def initialize(doc, tags = nil, ctx = nil, options = {}) # rubocop:disable Lint/MissingSuper
Create a document fragment.
def initialize(doc, tags = nil, ctx = nil, options = {}) # rubocop:disable Lint/MissingSuper 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
def serialize(options = {}, &block) # :nodoc:
def serialize(options = {}, &block) # :nodoc: # Bypass XML::Document.serialize which doesn't support options even # though XML::Node.serialize does! XML::Node.instance_method(:serialize).bind_call(self, options, &block) end