Markdown Parser
This is a simple Markdown to HTML parser implemented in Rust using the pest parser generator library. It can convert Markdown text into HTML.
Table of Contents
Installation
To use this Markdown to HTML parser in your Rust project, add it as a dependency in your Cargo.toml file:
[]
= "0.1.0"
Usage
As lib
First, import the library in your Rust code:
use parse_markdown;
Then, you can convert Markdown text to HTML using the parse_markdown function:
let markdown_text = "Your Markdown text here";
let html = parse_markdown;
println!;
As CLI
You can also use this Markdown to HTML parser as a command-line tool. To do this, first install the Rust toolchain on your system. Then, clone the repository and build the project:
Example
Here's an example of how to use the Markdown to HTML parser in a Rust program:
use parse_markdown;
Running this program will produce the following HTML output:
Heading 1Some italic and bold text.Heading 2More text.
Grammar
This parser uses a simple grammar to recognize Markdown elements. The grammar is defined in the markdown.pest file, and it includes rules for headers and paragraphs. Here's a brief overview of the grammar:
markdownIt consists of a sequence of elements, element_inner, text, and new_line, repeated zero or more times.elementsIt represents a choice between different types of elements: h1, h2, italic_text, bold_text, and code_text.h1Starts with "# " and is followed by a sequence of elements, element_inner, or text, ending with "\n".h2Similar to h1 but starts with "## ".italic_textRepresents text enclosed within either "_" or "*", denoting italic formatting.bold_textRepresents text enclosed within either "__" or "**", denoting bold formatting.code_textRepresents text enclosed within "`", denoting code formatting.element_innerRepresents a sequence of characters that are not "_", "*", "`", or "\n".textRepresents a sequence of characters that are not "\n".new_lineRepresents a newline character.
Contributing
Contributions are welcome! If you want to improve the parser, fix bugs, or add new features, please open an issue or submit a pull request on the GitHub repository.
License
[TODO] This Markdown to HTML parser is open-source and licensed under the MIT License. See the LICENSE file for more details.