unwrap method

  1. @override
Bs4Element? unwrap()

unwrap is the opposite of wrap.

It replaces a tag with whatever’s inside that tag.

It’s good for stripping out markup.

Like replaceWith, unwrap returns the tag that was replaced.

Implementation

@override
Bs4Element? unwrap() {
  for (final child in _element.nodes) {
    if (child.nodeType == Node.ELEMENT_NODE) {
      final index = _element.nodes.indexOf(child);
      final insideElement = _element.nodes.elementAt(index).clone(true);
      _element.nodes
        ..removeAt(index)
        ..insertAll(index, insideElement.nodes);
    }
  }
  return null;
}