Panpipe.AST.Node.transform

You're seeing just the function transform, go back to Panpipe.AST.Node module for more information.

Transforms the AST under the given Panpipe AST node by applying the given transformation function recursively.

The given function will be passed all nodes in pre-order and will replace those nodes for which the transformation function fun returns a non-nil replacement value. A node can also be replaced with a sequence of new nodes by returning a list of nodes in the transformation function. If you want to remove a node, you can return an empty list or a Panpipe.AST.Null node.

The transformation will be applied recursively also on children of the replaced values. You can prohibit that by returning the replacement in a halt tuple like this: {:halt, replacement}.

Examples

Panpipe.ast!(input: "file.md")
|> Panpipe.transform(fn
   %Panpipe.AST.Header{} = header ->
     %Panpipe.AST.Header{header | level: header.level + 1}
   _ -> nil
 end)

Panpipe.ast!(input: "file.md")
|> Panpipe.transform(fn
   %Panpipe.AST.Header{} = header ->
     {:halt, %Panpipe.AST.Header{header | level: header.level + 1}}
   _ -> nil
 end)