Skip to content

Commit cbec53e

Browse files
committed
Add a basic usage example to the README
1 parent 7738419 commit cbec53e

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,50 @@
55
[![GitHub Actions CI][github-actions-img]][github-actions-url]
66
[![CodeCov][codecov-img]][codecov-url]
77

8-
An abstract syntax tree representation of Markdown documents in Julia.
8+
A Julia package for working with Markdown documents in an [abstract syntax tree][ast-wiki] representation.
9+
As an example, the following Markdown
10+
11+
```markdown
12+
# Markdown document
13+
14+
Hello [world](https://example.com/)!
15+
```
16+
17+
can be represented as the following tree (in the [`@ast` macro DSL][mdast-astmacro]) using MarkdownAST
18+
19+
```julia
20+
using MarkdownAST: @ast, Document, Heading, Paragraph, Link
21+
ast = @ast Document() do
22+
Heading(1) do
23+
"Markdown document"
24+
end
25+
Paragraph() do
26+
"Hello "
27+
Link("https://example.com/", "") do
28+
"world"
29+
end
30+
"!"
31+
end
32+
end
33+
```
34+
35+
and the resulting [`Node` object][mdast-node] that contains information about the whole tree can be accessed, traversed, and, if need be, modified, e.g.
36+
37+
```julia-repl
38+
julia> for node in ast.children
39+
println("$(node.element) with $(length(node.children)) child nodes")
40+
end
41+
Heading(1) with 1 child nodes
42+
Paragraph() with 3 child nodes
43+
```
44+
45+
See the [documentation][docs-stable-url] for the full descriptions of the APIs that are available.
46+
47+
## Credits
48+
49+
The core parts of this package heavily derive from the [CommonMark.jl](https://github.com/MichaelHatherly/CommonMark.jl) package.
50+
Also, this packages does not provide a parser, and the users are encouraged to check out CommonMark.jl for that purpose.
51+
952

1053
[juliahub-version-img]: https://juliahub.com/docs/MarkdownAST/version.svg
1154
[juliahub-version-url]: https://juliahub.com/ui/Packages/MarkdownAST/6YkiC
@@ -15,3 +58,7 @@ An abstract syntax tree representation of Markdown documents in Julia.
1558
[docs-stable-url]: https://juliadocs.github.io/MarkdownAST.jl/stable/
1659
[codecov-img]: https://codecov.io/gh/JuliaDocs/MarkdownAST.jl/branch/main/graph/badge.svg?token=91XPUAQ2WE
1760
[codecov-url]: https://codecov.io/gh/JuliaDocs/MarkdownAST.jl
61+
62+
[ast-wiki]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
63+
[mdast-astmacro]: https://juliadocs.github.io/MarkdownAST.jl/stable/astmacro/#MarkdownAST.@ast
64+
[mdast-node]: https://juliadocs.github.io/MarkdownAST.jl/stable/node/#MarkdownAST.Node

0 commit comments

Comments
 (0)