Panpipe.AST.Node behaviour (Panpipe v0.3.0) View Source
Behaviour implemented by all nodes of the Panpipe AST.
The Panpipe AST is a Elixir representation of the
Pandoc data structure for a format-neutral representation of documents.
Each of the nodes of this AST data structure is a struct implementing the Panpipe.AST.Node
behaviour and directly matches the respective Pandoc element.
Each node type implements Elixir's Enumerable protocol as a pre-order tree
traversal.
Link to this section Summary
Functions
Returns if the given AST node is a block element.
Returns the type of child expected for the given AST node.
Returns if the given AST node is an inline element.
Produces the Pandoc AST data structure of the given Panpipe AST node.
Transforms the AST under the given Panpipe AST node by applying the given transformation function recursively.
Callbacks
Returns if the AST node module represents a block element.
Returns the type of child expected for a AST node.
Returns a list of the children of a node.
Returns if the AST node module represents an inline element.
Produces the Pandoc AST data structure of a Panpipe AST node.
Transforms an Panpipe AST node recursively.
Link to this section Types
Specs
t() :: module()
Link to this section Functions
Returns if the given AST node is a block element.
Returns the type of child expected for the given AST node.
This function returns either :block or :inline.
Returns if the given AST node is an inline element.
Produces the Pandoc AST data structure of the given Panpipe AST node.
Examples
iex> %Panpipe.AST.Header{level: 1, children: [%Panpipe.AST.Str{string: "Example"}]}
...> |> Panpipe.AST.Node.to_pandoc()
%{
"c" => [1, ["", [], []], [%{"c" => "Example", "t" => "Str"}]],
"t" => "Header"
}
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)
Link to this section Callbacks
Specs
block?() :: bool()
Returns if the AST node module represents a block element.
Specs
child_type() :: atom()
Returns the type of child expected for a AST node.
This function returns either :block or :inline.
Specs
Returns a list of the children of a node.
Specs
inline?() :: bool()
Returns if the AST node module represents an inline element.
Specs
Produces the Pandoc AST data structure of a Panpipe AST node.
Specs
Transforms an Panpipe AST node recursively.