#markdown-parser #syntax-tree #ast #markdown #peg #pest-parser #abstract

pegmd

A PEG based markdown parser for creating an Abstract Syntax Tree

4 releases

0.2.3 Aug 3, 2023
0.2.2 Aug 2, 2023
0.2.1 Jul 25, 2023
0.2.0 Jul 25, 2023
0.1.0 Jul 12, 2023

#2479 in Parser implementations

Download history 55/week @ 2024-02-19 38/week @ 2024-02-26 51/week @ 2024-04-01

51 downloads per month

MIT license

61KB
1.5K SLoC

Rust 1K SLoC // 0.0% comments Pest 211 SLoC // 0.0% comments

pegmd

Build crates.io docs
Parses a Markdown document that follows CommonMark v0.30 to an abstract syntax tree by defining its parsing expression grammar (PEG) with pest. The crate also optionally provides a transformer to emit the AST as HTML if the html feature included.

Usage

Creating an AST

The main function exported from the crate, ast::parse_document, accepts a &str and on success returns a Node with the same lifetime as the input.

Traversal

From there, you can traverse the tree by creating a struct that implements the traversal::Vistor trait and providing it to the Node::traverse method.

HTML Conversion

If the html feature is enabled, the crate provides the html::HTMLTransformer struct that implements the Visitor trait to create a well-formatted HTML output.

Unsupported

  • Document streaming. Because pest lacks support for streaming, this crate also can't read a document from a stream.

Current Limitations

While the end goal for the parser is to support the entire CommonMark spec, it currently doesn't support:

All of these are a WIP and will be added to the parser.

Dependencies

~2.2–3MB
~61K SLoC