# DataMark DataMark is an open source [[TypeScript]] library that lets you use [[Markdown]] as a **data format**. You parse a Markdown document into typed, validated objects, work with them in code, and write them back to Markdown. It's made by Lukas Mateffy (Mátéffy Software Research) and released under the MIT license. ## Why this matters Markdown is readable by humans, easy to edit, and it's what LLMs read and write all day long. But the moment an app needs to *read* a Markdown file as data (a plan, a checklist, a spec, a note with frontmatter), most people fall back on fragile regexes. DataMark swaps those regexes for a proper Abstract Syntax Tree (AST) and schema validation. The file stays plain Markdown for humans, and your code gets real types. ## How it works DataMark is split into three parts: - **Parse** (`datamark/parse`): `parse()` turns Markdown into a typed AST with a native section tree (sections, paragraphs, code blocks, lists, tables). Helpers like `find()`, `findAll()`, `textContent()`, `inlineText()`, `extractTodoItems()`, and `sectionsAtDepth()` let you query it - **Stringify** (`datamark/stringify`): builder primitives (`heading()`, `paragraph()`, `codeBlock()`, `list()`, `blockquote()`, `table()`, `frontmatter()`, `strong()`, `em()`, `link()`) that generate Markdown with consistent escaping and formatting - **Format** (`datamark`): `datamark()` ties everything together. You define a frontmatter schema, a body schema, a `parse` function, and a `stringify` function. The result is a reusable format that round-trips between Markdown and data Validation uses **Standard Schema v1**, so you can bring Zod, Valibot, ArkType, or TypeBox. When data doesn't match, it throws a `ValidationError`. The types come from the schema, so you don't write them twice and you don't cast anything. ```typescript const PlanFormat = datamark({ frontmatterSchema: z.object({ id: z.string() }), schema: z.object({ id: z.string(), title: z.string(), steps: z.array(z.object({ description: z.string(), scripts: z.array(z.string()), })), }), parse(doc) { /* ... */ }, stringify(data) { /* ... */ }, }); ``` Install it with `npm install datamark` or `bun add datamark`. ## DataMark and Knap DataMark pairs nicely with [[Knap]]. They go in opposite directions: - **Knap** turns data into Markdown using templates - **DataMark** turns Markdown back into data using schemas If you build tools on top of a Markdown vault (like I do with [[Obsidian]]), both belong in your toolbox. ## References - Official website: https://datamark.md - Source code: https://github.com/mateffy/datamark - NPM package: https://www.npmjs.com/package/datamark ## Related - [[Markdown]] - [[TypeScript]] - [[Knap]] - [[mq (CLI)]]