3 releases

0.1.2 Apr 10, 2021
0.1.1 Apr 9, 2021
0.1.0 Apr 9, 2021

#14 in #parse-markdown

Download history 162/week @ 2024-07-21 96/week @ 2024-07-28 54/week @ 2024-08-04 15/week @ 2024-08-11 27/week @ 2024-08-18 79/week @ 2024-08-25 46/week @ 2024-09-01 30/week @ 2024-09-08 17/week @ 2024-09-15 87/week @ 2024-09-22 46/week @ 2024-09-29 22/week @ 2024-10-06 79/week @ 2024-10-13 19/week @ 2024-10-20 26/week @ 2024-10-27 56/week @ 2024-11-03

186 downloads per month
Used in embed_anything

MIT/Apache

18KB
330 lines

Markdown Parser

😎 This a crate that can parse a markdown file.

Especially when you have front matters in your markdown file, this would help you to parse them.

Start

It is always easy to use this parser.

Just start to read a markdown file and parse it.

use markdown_parser::{
    read_file, Error
};

fn main() -> Result<(), Error> {
    let md = read_file("$PATH.md")?;
    let content = md.content();
    println!("{}", content);
    Ok(())
}

Front Matter

md-parser have 3 format for front matter, which can be confirmed in running time.

enum Format {
    JSON,
    YAML,
    TOML,
}

These formats are the most popular format for front matters, if you are not included, maybe you need to do parsing work by yourself.

you can goto documentation to see more about crate.

Adapt

Sometimes you have to transform your front matter in markdown.

For example, you have this:

---
date: 2020-01-02
title: it is yaml
categories:
  - rust
tags:
  - front-matter
  - md
---

And you need a toml-style front matter for your markdown rendering tasks.

So you have just use feature adapt to use transforming task which will load serde crates.

[dependencies.markdown-parser]
version = "*"
features = ["adapt"]

In fact, this task is quite common so feature adapt is enabled in default.

Now you can change md file like this:

use markdown_parser::*;

fn main() -> Result<(), Error> {
    let origin = read_file("yaml.md")?;
    let md = origin.adapt::<TomlAdapter, BasicObject>()?;
    md.write_file("toml.md")?;
    Ok(())
}

Dependencies

~3.5–5.5MB
~103K SLoC