1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//!# 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.
//!
//!```rust
//!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.
//!
//!```rust
//!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]("https://docs.rs/markdown-parser/") to see more about crate.
//!
//!# Adapt
//!
//!Sometimes you have to transform your front matter in markdown.
//!
//!For example, you have this:
//!
//!```yaml
//!---
//!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.
//!
//!```toml
//![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:
//!
//!```rust
//!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(())
//!}
//!```
//!

#[cfg(feature = "adapt")]
pub mod adapt;

#[cfg(feature = "adapt")]
pub use adapt::{de_fm, Adapter, BasicObject, EmptyObject, JsonAdapter, TomlAdapter, YamlAdapter};

mod error;
mod fs;
mod parser;

pub use error::{Error, ParseError};
pub use fs::{read_file, write_file};
pub use parser::{parse, parse_format, Format, Markdown, MarkdownResult};