Markdown Parser
A comprehensive Markdown to HTML converter built in Rust using Pest grammar. This project provides a command-line interface and library for parsing Markdown documents.
Installation
From crates.io
From Source
Usage
Command Line Interface
Convert a Markdown file to HTML
Parse Markdown text directly
Display help and credits
Library Usage
use ;
Grammar Examples
This parser supports the full CommonMark Markdown specification. Here are examples of supported syntax:
Headings
Text Formatting
**Bold text**
*Italic text*
~~Strikethrough text~~
__Underline text__
Links and Images
[Click here](https://example.com)

Inline Code
Use `code` for inline code snippets.
Code Blocks
```rust
fn main() {
}
```
Lists
Unordered Lists
- -*
Ordered Lists
1. 2.3.
Blockquotes
Horizontal Rules
---
***
___
Escaped Characters
\*literal asterisk\*
\[literal bracket\]
Grammar Structure
The parser uses Pest grammar for efficient parsing. The grammar is organized into the following main components:
Document Structure
document_structure = { SOI ~ (document_block ~ NEWLINE*)* ~ document_block? ~ EOI? }
document_block = {
document_heading
| document_quote
| code_fence
| document_unordered_list
| document_ordered_list
| thematic_break
| document_paragraph
}
Inline Content
inline_content = _{
image
| link
| text_formatting
| inline_code
| escape_sequence
| plain_text
}
Text Formatting
text_formatting = _{
bold_formatting
| italic_formatting
| strikethrough_formatting
| underline_formatting
}
Testing
Run the test suite:
Run with formatting and linting:
API Documentation
Core Functions
parse_markdown(input: &str)- Parse markdown string to syntax treestr_to_html(input: &str)- Convert markdown string to HTML vectorconvert_file_to_html(input: &Path, output: &Path)- Convert markdown file to HTML fileprint_html_to_console(input: &str)- Print HTML conversion to stdout
Error Types
Development
Project Structure
src/
├── main.rs # CLI application
├── lib.rs # Library implementation
└── grammar.pest # Pest grammar rules
tests/
└── grammar_tests.rs # Unit tests
Adding New Grammar Rules
- Add rule to
grammar.pest - Implement conversion function in
lib.rs - Add rule to
convert_to_htmlmatch statement - Add unit tests in
tests/grammar_tests.rs
Building for Development
Code Quality
- Formatting:
cargo fmt - Linting:
cargo clippy - Testing:
cargo test
Author
Zudilova Oryna - Initial work - arinamcnulty