Skip to main content

detect_front_matter

Function detect_front_matter 

Source
pub fn detect_front_matter(
    content: &str,
) -> Option<(FrontMatterFormat, &str, usize)>
Expand description

Locates the front-matter block without parsing it.

Returns the format, the raw block, and the byte offset at which the document body begins. Detection order is YAML, TOML, JSON, the same order extract_metadata uses; None means no shape matched.

ยงExample

use metadata_gen::metadata::{detect_front_matter, FrontMatterFormat};

let doc = "---\ntitle: T\n---\nBody";
let (format, raw, body_start) = detect_front_matter(doc).unwrap();
assert_eq!(format, FrontMatterFormat::Yaml);
assert_eq!(raw, "title: T");
assert_eq!(&doc[body_start..], "Body");