Format SDK
The Format SDK is the high-level layer of datamark. It turns Markdown documents into typed objects — and back again — through reusable, self-testing format definitions.
A format is a typed contract: you define a schema, a parse function that walks the AST using the Parse SDK, and optionally a stringify function for round-trip serialization using builder primitives from datamark/stringify. Add inline examples and your format becomes self-documenting and self-testing.
datamark()
The format factory — typed config, parse, stringify, test, docs
Frontmatter
Reading, validating, and typing frontmatter with schemas
Parsing Patterns
Navigate the AST, extract data, map Markdown to objects
Stringify
Serialize back to Markdown with builder primitives from datamark/stringify
Testing
Inline examples, self-testing formats, and CI integration
What the Format SDK provides
| Capability | Description |
|---|---|
| Typed frontmatter | frontmatterSchema validates and types doc.frontmatter before your parse function runs |
| Output validation | schema validates the return value of parse() automatically |
| Round-trip serialization | stringify turns typed data back into Markdown via datamark/stringify |
| Self-testing | examples are validated by .test() — add them once, test forever |
| Builder primitives | heading(), list(), codeBlock(), frontmatter() and more from datamark/stringify |
| Standard Schema support | Works with Zod, Valibot, ArkType, TypeBox, and any Standard Schema v1 validator |
How the layers fit together
datamark/stringify → heading(), list(), codeBlock(), frontmatter() …
↑
Format SDK → datamark({ schema, parse, stringify, examples })
↑
Parse SDK → parse(), findAll(), textContent(), isCodeBlock() …
↑
marked + yaml → Markdown lexer + YAML parserThe Format SDK is built on top of the Parse SDK. Every parse function receives a Document from the Parse SDK and uses its utilities (findAll, textContent, isCodeBlock, etc.) to extract data. Every stringify function uses datamark/stringify primitives to reconstruct Markdown cleanly.
For raw AST manipulation without schemas or serialization, use the Parse SDK directly.