1
use pulldown_cmark_frontmatter::FrontmatterExtractor;
2

            
3
use crate::shared::ExampleAttributes;
4

            
5
mod shared;
6

            
7
1
fn main() {
8
1
    // begin rustme snippet: readme
9
1
    // This example extracts the frontmatter from the Markdown,
10
1
    // `FrontmatterExtractor::extract()` which stops parsing the Markdown
11
1
    // document after the frontmatter extraction is complete.
12
1
    let extractor = FrontmatterExtractor::from_markdown(include_str!("../frontmatter-example.md"));
13
1
    let frontmatter = extractor.extract().expect("frontmatter not detected");
14
1
    assert_eq!(
15
1
        frontmatter.title.expect("title not detected"),
16
1
        "Frontmatter Example Document"
17
1
    );
18
1
    let code_block = frontmatter.code_block.expect("code block not detected");
19
1
    assert_eq!(code_block.language.as_deref(), Some("toml"));
20
1
    let attrs: ExampleAttributes = toml::from_str(&code_block.source).expect("invalid toml");
21
1
    assert_eq!(attrs.author, "https://fosstodon.org/@ecton");
22
    // end rustme snippet
23
1
}
24

            
25
#[test]
26
1
fn runs() {
27
1
    main()
28
1
}