class Nokogiri::XML::Node

def wrap(node_or_tags)


#
#
#
doc.to_html
doc.at_css("a").wrap(doc.create_element("div"))
HTML

asdf

doc = Nokogiri::HTML5(<<~HTML)

*Example* with a +Node+ argument:

#
#
# =>
doc.to_html
doc.at_css("a").wrap("
")
HTML

asdf

doc = Nokogiri::HTML5(<<~HTML)

*Example* with a +String+ argument:

Also see NodeSet#wrap

[Returns] +self+, to support chaining.

An element that is `#dup`ed and used as the wrapper.
- *node* (Nokogiri::XML::Node)
fragment has multiple roots, the first root node is used as the wrapper.
as the context node for parsing; otherwise the associated document is used. If the parsed
Markup that is parsed and used as the wrapper. This node's parent, if it exists, is used
- *markup* (String)
[Parameters]

Wrap this Node with the node parsed from +markup+ or a dup of the +node+.

wrap(node) -> self
wrap(markup) -> self
:call-seq:
def wrap(node_or_tags)
  case node_or_tags
  when String
    context_node = parent || document
    new_parent = context_node.coerce(node_or_tags).first
    if new_parent.nil?
      raise "Failed to parse '#{node_or_tags}' in the context of a '#{context_node.name}' element"
    end
  when Node
    new_parent = node_or_tags.dup
  else
    raise ArgumentError, "Requires a String or Node argument, and cannot accept a #{node_or_tags.class}"
  end
  if parent
    add_next_sibling(new_parent)
  else
    new_parent.unlink
  end
  new_parent.add_child(self)
  self
end