Stringify SDK

Stringify SDK

The Stringify SDK turns typed data and AST nodes back into Markdown strings. It is the inverse of the Parse SDK: where parse() consumes Markdown, the Stringify SDK produces it.

Use it directly when you need to build Markdown output from structured data, or as the serialization layer inside a Format SDK format definition.

What the Stringify SDK provides

CapabilityFunctions
Block buildersfrontmatter(), heading(), paragraph(), codeBlock(), list(), blockquote(), horizontalRule()
Inline buildersstrong(), em(), codeSpan(), link(), image(), strikethrough()
Document serializationstringify(), toMarkdown()
YAML helpersstringifyYaml()

Two ways to use it

1. Builder primitives

Compose Markdown strings from data without raw string concatenation:

import { frontmatter, heading, paragraph, list, codeBlock } from "datamark/stringify";

const markdown = [
  frontmatter({ title: "API Guide" }),
  heading("Authentication", 2),
  paragraph("Use Bearer tokens for all requests."),
  codeBlock("fetch('/api', { headers: { Authorization: 'Bearer ...' } });", "javascript"),
].join("\n\n");

2. Document serialization

Serialize a full Document AST back to Markdown:

import { stringify } from "datamark";

const output = stringify(doc);
// Clean Markdown with frontmatter, headings, and all content restored

How the layers fit together

    Parse SDK      →  parse(), findAll(), textContent(), isCodeBlock() …

   Format SDK      →  datamark({ schema, parse, stringify, examples })

    Stringify SDK  →  heading(), list(), codeBlock(), frontmatter() …

The Format SDK sits between the two: it uses the Parse SDK to turn Markdown into data, and the Stringify SDK to turn data back into Markdown.

When to use the Stringify SDK directly

  • You need to generate Markdown output from structured data
  • You want type-safe builder functions instead of template strings
  • You need to serialize individual AST nodes, not full documents
  • You're building custom tooling that produces Markdown

For round-trip format definitions with validation, the Format SDK is the better starting point.

On this page