pub fn detect_format(raw_frontmatter: &str) -> Result<Format, Error>
Expand description
Detects the format of the extracted frontmatter.
This function analyzes the raw frontmatter and determines whether it is in YAML, TOML, or JSON format by examining the structure of the data.
§Arguments
raw_frontmatter
- The extracted frontmatter as a string slice.
§Returns
A Result
containing the detected Format
(either Json
, Toml
, or Yaml
).
§Errors
Error::InvalidFormat
: If the format cannot be determined.
§Example
use frontmatter_gen::extractor::detect_format;
use frontmatter_gen::Format;
let raw = "---\ntitle: Example\n---";
let format = detect_format(raw).unwrap();
assert_eq!(format, Format::Yaml);