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, and off silently coerce into booleans. Under YAML 1.2, only true and false resolve as booleans, keeping country codes and short tokens intact as Value::String.
  • Explicit YAML Tag Preservation: Tagged scalars and mappings (such as !custom value or !include path.yaml) are preserved losslessly as Value::Tagged(tag_name, Box<Value>) and accessible via Value::as_tagged().
  • Root Mapping Requirement: The top-level YAML value must be a mapping; scalar or sequence roots return ParseError::InvalidYaml.
markdown — YAML 1.2 frontmatter
---
title: "Deterministic YAML 1.2"
country: NO
published: true
custom: !slug my-article-slug
---
# Article Body

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.
markdown — TOML 1.1 frontmatter
+++
title = "TOML 1.1 Frontmatter"
weight = 10
date = 2026-10-31T12:00:00Z
[taxonomies]
categories = ["systems", "rust"]
+++
# TOML Document Body

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_frontmatter tracks 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::Number inside Value::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):

rust — cross-format conversion
use frontmatter_gen::{extract, Format};
use frontmatter_gen::parser::to_string;
 
let (fm, _body) = extract("---\ntitle: Convert Me\ncount: 42\n---\nBody")?;
let as_toml = to_string(&fm, Format::Toml)?;
let as_json = to_string(&fm, Format::Json)?;