frontmatter_gen::extractor

Function extract_delimited_frontmatter

Source
pub fn extract_delimited_frontmatter<'a>(
    content: &'a str,
    start_delim: &str,
    end_delim: &str,
) -> Option<&'a str>
Expand description

Extracts frontmatter enclosed by the given start and end delimiters.

This function checks for frontmatter enclosed by delimiters like --- for YAML or +++ for TOML. It returns the extracted frontmatter if the delimiters are found.

§Arguments

  • content - The full content string containing frontmatter.
  • start_delim - The starting delimiter (e.g., ---\n for YAML).
  • end_delim - The ending delimiter (e.g., \n---\n for YAML).

§Returns

An Option containing the extracted frontmatter as a string slice. Returns None if the delimiters are not found.

§Example

use frontmatter_gen::extractor::extract_delimited_frontmatter;
let content = "---\ntitle: Example\n---\nContent";
let frontmatter = extract_delimited_frontmatter(content, "---\n", "\n---\n").unwrap();
assert_eq!(frontmatter, "title: Example");