mapNodes method
Depth-first map: Applies transform to each node, rebuilding the tree bottom-up.
Example usage:
final cleaned = doc.mapNodes((it) => it is SpaceNode ? TextNode(" ") : it);
Implementation
LatexNode mapNodes(LatexNode Function(LatexNode node) transform) {
final mappedChildren = children()
.map((it) => it.mapNodes(transform))
.toList();
final rebuilt = mappedChildren.isEmpty
? this
: withChildren(mappedChildren);
return transform(rebuilt);
}