pruneEmptyContainers function

void pruneEmptyContainers(
  1. FNode node,
  2. Root root
)

Cleans node from the document if it's an empty InlineContainerNode. Climbs the tree and repeats if necessary (ex pruneEmpty).

Implementation

void pruneEmptyContainers(FNode node, Root root) {
  if (node is! InlineContainerNode) return;
  final children = (node as InlineContainerNode).getChildren();
  if (children.isNotEmpty) return;
  final parent = findParent(root, node);
  if (parent == null) return;
  removeNode(root, node);
  if (parent is InlineContainerNode) pruneEmptyContainers(parent, root);
}