Earmark.AstTools (Earmark v1.4.16-pre) View Source

Tools for AST manipulation

Link to this section Summary

Functions

Convenience function to access an attribute

A helper to merge attributes in their cannonical representation

A convenience function that extracts the original attributes to be merged with new attributes and puts the result into the node again

Link to this section Functions

Link to this function

find_att_in_node(node_or_atts, att)

View Source

Convenience function to access an attribute

iex(3)> find_att_in_node({"a", [{"class", "link"}], [], %{}}, "class")
"link"

iex(4)> find_att_in_node({"a", [{"class", "link"}], [], %{}}, "target")
nil

iex(5)> find_att_in_node({"a", [{"class", "link"}], [], %{}}, "target", :default)
:default

iex(6)> find_att_in_node([{"class", "link"}], "class")
"link"

iex(7)> find_att_in_node([{"class", "link"}], "target")
nil

iex(8)> find_att_in_node([{"class", "link"}], "target", :default)
:default
Link to this function

find_att_in_node(node_or_atts, att, default)

View Source

A helper to merge attributes in their cannonical representation

iex(0)> merge_atts([{"href", "url"}], target: "_blank")
[{"href", "url"}, {"target", "_blank"}]

iex(1)> merge_atts([{"href", "url"}, {"target", "nonsense"}], %{"target" => "_blank"})
[{"href", "url"}, {"target", "_blank nonsense"}]

iex(2)>  merge_atts([{"href", "url"}, {"target", "nonsense"}, {"alt", "nowhere"}],
...(2)>              [{"target", "_blank"}, title: "where?"])
[{"alt", "nowhere"}, {"href", "url"}, {"target", "_blank nonsense"}, {"title", "where?"}]
Link to this function

merge_atts_in_node(arg, new_atts)

View Source

A convenience function that extracts the original attributes to be merged with new attributes and puts the result into the node again

iex(9)> merge_atts_in_node({"img", [{"src", "there"}, {"alt", "there"}], [], %{some: "meta"}}, alt: "here")
{"img", [{"alt", "here there"}, {"src", "there"}], [], %{some: "meta"}}