markdown_parser/
lib.rs

1//!# Markdown Parser
2//!
3//!😎 This a crate that can parse a markdown file.
4//!
5//!Especially when you have front matters in your markdown file, this would help you to parse them.
6//!
7//!# Start
8//!
9//!It is always easy to use this parser.
10//!
11//!Just start to read a markdown file and parse it.
12//!
13//!```rust
14//!use markdown_parser::{
15//!    read_file, Error
16//!};
17//!
18//!fn main() -> Result<(), Error> {
19//!    let md = read_file("$PATH.md")?;
20//!    let content = md.content();
21//!    println!("{}", content);
22//!    Ok(())
23//!}
24//!```
25//!
26//!# Front Matter
27//!
28//!`md-parser` have 3 format for `front matter`, which can be confirmed in running time.
29//!
30//!```rust
31//!enum Format {
32//!    JSON,
33//!    YAML,
34//!    TOML,
35//!}
36//!```
37//!
38//!These formats are the most popular format for front matters, if you are not included, maybe you need to do parsing work by yourself.
39//!
40//!you can goto [documentation]("https://docs.rs/markdown-parser/") to see more about crate.
41//!
42//!# Adapt
43//!
44//!Sometimes you have to transform your front matter in markdown.
45//!
46//!For example, you have this:
47//!
48//!```yaml
49//!---
50//!date: 2020-01-02
51//!title: it is yaml
52//!categories:
53//!  - rust
54//!tags:
55//!  - front-matter
56//!  - md
57//!---
58//!
59//!```
60//!
61//!And you need a toml-style front matter for your markdown rendering tasks.
62//!
63//!So you have just use feature `adapt` to use transforming task which will load `serde` crates.
64//!
65//!```toml
66//![dependencies.markdown-parser]
67//!version = "*"
68//!features = ["adapt"]
69//!```
70//!
71//!In fact, this task is quite common so feature `adapt` is enabled in default.
72//!
73//!Now you can change md file like this:
74//!
75//!```rust
76//!use markdown_parser::*;
77//!
78//!fn main() -> Result<(), Error> {
79//!    let origin = read_file("yaml.md")?;
80//!    let md = origin.adapt::<TomlAdapter, BasicObject>()?;
81//!    md.write_file("toml.md")?;
82//!    Ok(())
83//!}
84//!```
85//!
86
87#[cfg(feature = "adapt")]
88pub mod adapt;
89
90#[cfg(feature = "adapt")]
91pub use adapt::{de_fm, Adapter, BasicObject, EmptyObject, JsonAdapter, TomlAdapter, YamlAdapter};
92
93mod error;
94mod fs;
95mod parser;
96
97pub use error::{Error, ParseError};
98pub use fs::{read_file, write_file};
99pub use parser::{parse, parse_format, Format, Markdown, MarkdownResult};