A Julia package for working with Markdown documents in an abstract syntax tree representation. As an example, the following Markdown
# Markdown document
Hello [world](https://example.com/)!
can be represented as the following tree (in the @ast
macro DSL) using MarkdownAST
using MarkdownAST: @ast, Document, Heading, Paragraph, Link
ast = @ast Document() do
Heading(1) do
"Markdown document"
end
Paragraph() do
"Hello "
Link("https://example.com/", "") do
"world"
end
"!"
end
end
and the resulting Node
object that contains information about the whole tree can be accessed, traversed, and, if need be, modified, e.g.
julia> for node in ast.children
println("$(node.element) with $(length(node.children)) child nodes")
end
Heading(1) with 1 child nodes
Paragraph() with 3 child nodes
See the documentation for the full descriptions of the APIs that are available.
The core parts of this package heavily derive from the CommonMark.jl package. Also, this packages does not provide a parser, and the users are encouraged to check out CommonMark.jl for that purpose.