class Nokogiri::HTML5::DocumentFragment

💡 HTML5 functionality is not available when running JRuby.
Since v1.12.0

def extract_params(params) # :nodoc:

: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(


Node, or a hypothetical tag named as specified, is the parent of the fragment subtree.
If a context node is specified using +context:+, then the parser will behave as if that

=== Context \Node

[Returns] HTML5::DocumentFragment

See rdoc-ref:HTML5@Parsing+options for a complete description of these parsing options.

elements as text. (default +false+)
- +parse_noscript_content_as_text:+ (Boolean) Whether to parse the content of +noscript+

element. (default +Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES+)
- +max_attributes:+ (Integer) The maximum number of attributes allowed on an

+Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH+)
- +max_tree_depth:+ (Integer) The maximum depth of the parse tree. (default

+Nokogiri::Gumbo::DEFAULT_MAX_ERRORS+ which is currently 0)
- +max_errors:+ (Integer) The maximum number of parse errors to record. (default

which to parse the document fragment. (default +"body"+)
- +context:+ (String | Nokogiri::XML::Node) The node, or the name of an HTML5 element, in

encoding is handled by the parser.
based on the document content. Also see Nokogiri::HTML5 for a longer explanation of how
used when processing the document. When not provided, the encoding will be determined
- +encoding:+ (String | Encoding) The encoding, or name of the encoding, that should be
[Optional Keyword Arguments]

- +input+ (String) The content to be parsed.
[Optional Parameters]

- +document+ (HTML5::Document) The parent document to associate the returned fragment with.
[Required Parameters]

rather than call this method directly.
💡 It's recommended to use either HTML5::DocumentFragment.parse or HTML5::Node#fragment

Parse \HTML5 fragment input from a String, and return a new HTML5::DocumentFragment.

new(document, input, **options) → HTML5::DocumentFragment
:call-seq:
def initialize(
  doc, input = nil,
  context_ = nil, positional_options_hash = nil,
  context: context_,
  **options
) # rubocop:disable Lint/MissingSuper
  unless positional_options_hash.nil? || positional_options_hash.empty?
    options.merge!(positional_options_hash)
  end
  @document = doc
  @errors = []
  return self unless input
  input = Nokogiri::HTML5.read_and_encode(input, nil)
  context = options.delete(:context) if options.key?(:context)
  options[:max_attributes] ||= Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES
  options[:max_errors] ||= options.delete(:max_parse_errors) || Nokogiri::Gumbo::DEFAULT_MAX_ERRORS
  options[:max_tree_depth] ||= Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH
  Nokogiri::Gumbo.fragment(self, input, context, **options)
end

def parse(


Node, or a hypothetical tag named as specified, is the parent of the fragment subtree.
If a context node is specified using +context:+, then the parser will behave as if that

=== Context \Node

[Returns] Nokogiri::HTML5::DocumentFragment

See rdoc-ref:HTML5@Parsing+options for a complete description of these parsing options.

elements as text. (default +false+)
- +parse_noscript_content_as_text:+ (Boolean) Whether to parse the content of +noscript+

element. (default +Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES+)
- +max_attributes:+ (Integer) The maximum number of attributes allowed on an

+Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH+)
- +max_tree_depth:+ (Integer) The maximum depth of the parse tree. (default

+Nokogiri::Gumbo::DEFAULT_MAX_ERRORS+ which is currently 0)
- +max_errors:+ (Integer) The maximum number of parse errors to record. (default

information. (default +"body"+)
context" of which to parse the document fragment. See below for more
- +context:+ (String | Nokogiri::XML::Node) The node, or the name of an HTML5 element, "in

encoding is handled by the parser.
based on the document content. Also see Nokogiri::HTML5 for a longer explanation of how
used when processing the document. When not provided, the encoding will be determined
- +encoding:+ (String | Encoding) The encoding, or name of the encoding, that should be
[Optional Keyword Arguments]

- +input+ (String | IO) The HTML5 document fragment to parse.
[Parameters]

method creates a new, empty HTML5::Document to contain the fragment.
Parse \HTML5 fragment input from a String, and return a new HTML5::DocumentFragment. This

parse(input, **options) → HTML5::DocumentFragment
:call-seq:
def parse(
  input,
  encoding_ = nil, positional_options_hash = nil,
  encoding: encoding_, **options
)
  unless positional_options_hash.nil? || positional_options_hash.empty?
    options.merge!(positional_options_hash)
  end
  context = options.delete(:context)
  document = HTML5::Document.new
  document.encoding = "UTF-8"
  input = HTML5.read_and_encode(input, encoding)
  new(document, input, context, options)
end

def serialize(options = {}, &block) # :nodoc:

: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