Skip to main content

extract_front_matter_data

Function extract_front_matter_data 

Source
pub fn extract_front_matter_data(content: &str) -> Result<(Value, String)>
Expand description

Extracts and parses front matter from content, supporting YAML (---), TOML (+++), and JSON ({}) delimiters.

Returns a tuple of (parsed front matter as JSON Value, remaining content). If no front matter is found, returns (Value::Null, original content).

§Arguments

  • content - A string slice that holds the content to process.

§Returns

  • Result<(Value, String)> - Parsed front matter and remaining content, or an error.

§Errors

This function will return an error if:

  • The input is empty or exceeds the maximum allowed size.
  • The front matter is invalidly formatted or cannot be parsed.

§Examples

use html_generator::utils::extract_front_matter_data;
use serde_json::json;

let content = "---\ntitle: My Page\n---\n# Hello, world!";
let (data, rest) = extract_front_matter_data(content).unwrap();
assert_eq!(data["title"], "My Page");
assert_eq!(rest, "# Hello, world!");