Specifications Matrix
Supported Frontmatter Formats & Specifications
Full YAML 1.2, TOML 1.1, and JSON frontmatter extraction, automatic format detection, and lossless cross-format conversion.
Frontmatter Gen supports the three primary frontmatter formats used across static site generators, documentation engines, and content management systems. All three formats deserialize into the same Frontmatter (HashMap<String, Value>) representation and can be converted into one another via frontmatter_gen::parser::to_string.
| Format | Fence / Delimiter | Underlying Parser | Specification & Key Guarantees |
|---|---|---|---|
| YAML 1.2 | --- ... --- | noyalib (Pure Rust) | YAML 1.2 Core Schema; no Norway problem; explicit tags preserved as Value::Tagged. |
| TOML 1.1 | +++ ... +++ | toml | TOML 1.1 tables, inline tables, arrays of tables, and ISO 8601 datetimes converted to strings. |
| JSON | { ... } or fenced JSON | serde_json | RFC 8259 balanced brace tracking with string-literal and escape-sequence awareness. |
1. YAML 1.2 Frontmatter (---) via noyalib
YAML is the default frontmatter format across Jekyll, Astro, Docusaurus, Eleventy, and Markdown documentation portals. Unlike legacy Rust crates built on archived serde_yaml (YAML 1.1), frontmatter-gen uses noyalib, a pure-Rust YAML 1.2 parser with zero unsafe code:
- No YAML 1.1 Norway Problem: In YAML 1.1, unquoted strings like
NO,no,on, andoffsilently coerce into booleans. Under YAML 1.2, onlytrueandfalseresolve as booleans, keeping country codes and short tokens intact asValue::String. - Explicit YAML Tag Preservation: Tagged scalars and mappings (such as
!custom valueor!include path.yaml) are preserved losslessly asValue::Tagged(tag_name, Box<Value>)and accessible viaValue::as_tagged(). - Root Mapping Requirement: The top-level YAML value must be a mapping; scalar or sequence roots return
ParseError::InvalidYaml.
2. TOML 1.1 Frontmatter (+++) via toml
TOML frontmatter is standard in Hugo, Zola, and Rust documentation pipelines. A TOML header opens with +++ on the first line and closes with a matching +++ fence:
- Native Datetime Normalization: TOML native datetimes (
toml::Value::Datetime) are automatically converted into their canonical ISO 8601 string representation (Value::String) for uniform downstream template rendering. - Nested Tables & Arrays: Dotted keys, inline tables, and nested sections map directly to nested
Value::Object(Box<Frontmatter>)structures.
3. JSON Frontmatter ({ ... }) via serde_json
JSON frontmatter is widely used in automated CMS exports and machine-generated Markdown documents. frontmatter-gen supports both standalone leading JSON objects and fenced JSON blocks:
- Balanced Brace Scanner:
extract_json_frontmattertracks brace depth while respecting quoted string literals and backslash escapes (\"), ensuring braces inside string values never prematurely terminate extraction. - Exact Numeric Representation: Numbers are stored as
serde_json::NumberinsideValue::Number, preserving 64-bit signed/unsigned integers and IEEE 754 floats.
4. Cross-Format Serialization (parser::to_string)
Because all three formats deserialize into Frontmatter, converting between YAML, TOML, and JSON requires a single call to frontmatter_gen::parser::to_string(&fm, target_format):