Skip to main content

extract_metadata_with_body

Function extract_metadata_with_body 

Source
pub fn extract_metadata_with_body(
    content: &str,
) -> Result<(Metadata, &str), MetadataError>
Expand description

Extracts metadata and returns the document body alongside it.

The body is the text after the closing delimiter, with one leading newline removed so a --- fence on its own line does not leave an empty first line. extract_metadata is this without the body.

§Errors

The same errors as extract_metadata.

§Example

use metadata_gen::metadata::extract_metadata_with_body;

let doc = "---\ntitle: T\n---\n# Heading\n\nText";
let (meta, body) = extract_metadata_with_body(doc).unwrap();
assert_eq!(meta.get("title").map(String::as_str), Some("T"));
assert_eq!(body, "# Heading\n\nText");