class Nokogiri::HTML4::DocumentFragment

def initialize(


parent of the fragment subtree.
calling XML::Node#parse on that node, so the parser will behave as if that Node is the
If a context node is specified using +context:+, then the fragment will be created by

=== Context \Node

[Returns] HTML4::DocumentFragment

can be configured before parsing. See ParseOptions for more information.
If a block is given, a Nokogiri::XML::ParseOptions object is yielded to the block which
[Yields]

+ParseOptions::DEFAULT_HTML+.
behaviors during parsing. See ParseOptions for more information. The default value is
- +options:+ (Nokogiri::XML::ParseOptions) Configuration object that determines some

below for more information.
- +context:+ (Nokogiri::XML::Node) The context node for the subtree created. See
[Optional Keyword Arguments]

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

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

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

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

new(document, input, context:, options:) { |options| ... } → HTML4::DocumentFragment
new(document, input) { |options| ... } → HTML4::DocumentFragment
new(document) { |options| ... } → HTML4::DocumentFragment
:call-seq:
def initialize(
  document, input = nil,
  context_ = nil, options_ = XML::ParseOptions::DEFAULT_HTML,
  context: context_, options: options_
) # rubocop:disable Lint/MissingSuper
  return self unless input
  options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
  @parse_options = options
  yield options if block_given?
  if context
    preexisting_errors = document.errors.dup
    node_set = context.parse("<div>#{input}</div>", options)
    node_set.first.children.each { |child| child.parent = self } unless node_set.empty?
    self.errors = document.errors - preexisting_errors
  else
    # This is a horrible hack, but I don't care
    path = if /^\s*?<body/i.match?(input)
      "/html/body"
    else
      "/html/body/node()"
    end
    temp_doc = HTML4::Document.parse("<html><body>#{input}", nil, document.encoding, options)
    temp_doc.xpath(path).each { |child| child.parent = self }
    self.errors = temp_doc.errors
  end
  children
end