YAML Front Matter (YFM) Parser
yaml-front-matter parses a valid YAML string into a struct which
implements the DeserializeOwned trait from serde.
Consider the following YAML content on the top of your markdown file:
---
title: 'Parsing a Markdown file metadata into a struct'
description: 'This tutorial walks you through the practice of parsing markdown files for metadata'
tags:
similar_posts:
- 'Rendering markdown'
- 'Using Rust to render markdown'
date: '2021-09-13T03:48:00'
favorite_numbers:
- 3.14
- 1970
- 12345
---
This crate takes care of extracting this header from your markdown file and
parse extracted data using serde and serde_yaml.
Example
use Deserialize;
use YamlFrontMatter;
const SIMPLE_MARKDOWN_YFM: &str = r#"
---
title: 'Parsing a Markdown file metadata into a struct'
description: 'This tutorial walks you through the practice of parsing markdown files for metadata'
tags: ['markdown', 'rust', 'files', 'parsing', 'metadata']
similar_posts:
- 'Rendering markdown'
- 'Using Rust to render markdown'
date: '2021-09-13T03:48:00'
favorite_numbers:
- 3.14
- 1970
- 12345
---
# Parsing a **Markdown** file metadata into a `struct`
> This tutorial walks you through the practice of parsing markdown files for metadata
"#;
let result = .unwrap;
let Metadata = result;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;