Format SDK

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.

What the Format SDK provides

CapabilityDescription
Typed frontmatterfrontmatterSchema validates and types doc.frontmatter before your parse function runs
Output validationschema validates the return value of parse() automatically
Round-trip serializationstringify turns typed data back into Markdown via datamark/stringify
Self-testingexamples are validated by .test() — add them once, test forever
Builder primitivesheading(), list(), codeBlock(), frontmatter() and more from datamark/stringify
Standard Schema supportWorks 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 parser

The 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.

On this page