A powerful, flexible, Markdown-based authoring framework.
Markdoc is a Markdown-based syntax and toolchain for creating custom documentation sites and experiences.
We designed Markdoc to power Stripe's public docs, our largest and most complex content site.
Installation
To get started with Markdoc, first install the library:
pnpm add @markdoc/markdoc
and import it in your app:
const Markdoc = require('@markdoc/markdoc');
or if you are using ESM
import Markdoc from '@markdoc/markdoc';
then use Markdoc in your app or tool:
const doc = `
# Markdoc README
{% image src="/logo.svg" /%}
`;
const ast = Markdoc.parse(doc);
const content = Markdoc.transform(ast);
return Markdoc.renderers.react(content, React);
Check out our docs for more guidance on how to use Markdoc.
Rendering Markdown
Markdoc.renderers.md renders the same transformed content as Markdown
(CommonMark with GFM tables and strikethrough), for example to serve docs to
LLMs or other plain-text consumers:
const ast = Markdoc.parse(doc);
const content = Markdoc.transform(ast, config);
const markdown = Markdoc.renderers.md(content);
The renderer takes the output of Markdoc.transform, so variables, conditionals,
and partials are already resolved. A string passed to the renderer is treated as
literal text, not as Markdoc source. Information removed during transformation,
such as frontmatter, annotations, and the original whitespace or Markdown
markers, is not reconstructed. The output is Markdown, not markup-free text:
literal text is escaped so that it keeps its meaning.
Standard Markdoc nodes render without configuration. Other elements, including
custom components, render their children. To convert a component differently,
add a handler keyed by its rendered name (Tag.name, such as Callout, rather
than the source tag name callout). Handlers return Markdown AST nodes built
with Markdoc.Ast.Node; 'children' renders only the children and 'none'
omits the whole subtree:
const markdown = Markdoc.renderers.md(content, {
handlers: {
Callout: (tag, { renderChildren }) =>
new Markdoc.Ast.Node('blockquote', {}, renderChildren(tag.children)),
Layout: 'children',
CopyButton: 'none',
},
});
Handlers may override standard elements, such as table or pre, and may not
return Markdoc tags or unresolved variables.
Pass data to make render-time values, such as a base URL, available to every
handler as context.data. Values that change the content itself belong in
variables when transforming.
By default, an error thrown by a handler, or invalid nodes returned by one,
aborts rendering. Pass onError to render the rest of the document instead. It
receives the error, the tag whose handler failed, and the handler context, and
returns nodes to render in place of the tag, or nothing to omit it. Errors are
reported at the nearest failing tag, and errors thrown from onError abort
rendering:
const markdown = Markdoc.renderers.md(content, {
handlers,
data: { baseUrl: 'https://example.com' },
onError(error, tag, { renderChildren }) {
console.error(error);
return renderChildren(tag.children);
},
});
Tables render as compact GFM pipe tables with a single header row. Headerless
tables get an empty header, and ragged rows are padded. Cell spans, nested
tables, and block content inside cells (such as paragraphs, lists, and code
blocks) cannot be represented, so their text is kept in row order on a single
line; use a table handler for richer output.
The Markdown renderer does not sanitize HTML or validate URLs: link and image
destinations are kept as supplied, including relative URLs.
Agent skills
The Markdoc agent plugin
provides setup-markdoc, write-markdoc, and create-markdoc-tag skills for
Codex and Claude Code. Install them through skills.sh:
pnpm dlx skills add https://markdoc.dev
See the plugin README for marketplace installation and local testing.
TypeScript
The public renderer types require @types/react, even when using only the
Markdown parser or HTML renderer. Package managers that install peer dependencies
automatically will install it; otherwise, install @types/react explicitly.
The React runtime is optional.
For TypeScript projects that use a bundler, use:
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"target": "esnext", // works with es2015 or greater
"esModuleInterop": true
}
}