Skip to content

Abstract syntax tree representation of Markdown documents in Julia

License

Notifications You must be signed in to change notification settings

JuliaDocs/MarkdownAST.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MarkdownAST

Version Documentation GitHub Actions CI CodeCov PkgEval

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.

Credits

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.