On this page
The short answerWhat Markdoc changes before publicationWhy Markdoc examples break or go untestedBuild the illustrative projectInspect a raw scanValidate and write a scan-ready copyTest structural and code failures separatelyTriage findingsWhere DocsAlive fitsThe sources we checkedFAQThe short answer
Validate Markdoc with the configuration your site uses, transform the pages, and test the examples readers receive. Validation catches structural problems such as broken tags; executing the transformed examples checks a different promise: that the published code still works.
On raw Markdoc, engine 0.6.3 of DocsAlive does not substitute variables or expand partials. It scans partial files as pages of their own, runs blocks from every if/else branch, and does not group custom tabs. It does not treat .mdoc files as pages. Generate a scan-ready copy from Markdoc’s transform, then scan that copy with its limits documented below.
What Markdoc changes before publication
Markdoc syntax is a superset of CommonMark Markdown. Its curly-brace-percent tags have names, attributes and bodies, and can be self-closing. Built-in tags include if, else, table and partial. A project can also define tags and nodes for its own presentation.
Variables have a dollar-sign prefix, must be JSON-serializable and resolve during transformation. A variable tag such as the version variable can therefore change a command inside a fence before a reader copies it. A partial tag references another file through its file attribute; the partial is registered as a parsed abstract syntax tree and can receive variables. An if tag selects content based on a condition.
The fence node has content, language and process attributes. By default, Markdoc parses tags inside a fence. The process=false annotation makes the fence content plain text instead, useful when the documentation needs to show a tag itself. Annotations place attributes after a node in a separate tag. Comments require the tokenizer’s allowComments option.
Rendering has three phases. Parse turns a source string into an abstract syntax tree. Transform combines that tree with configuration and resolves variables into a renderable tree. Render produces an output such as HTML or React. validate checks the parsed tree against configuration and returns errors; custom validation functions and attribute types can add project-specific checks. See rendering and validation.
This separation is central to testing. Valid source may produce a working page, but validation does not execute code. A raw source scan may find fences that readers never see, miss setup supplied by a partial, or run a literal variable tag where the published page contains a concrete version.
Why Markdoc examples break or go untested
Markdoc is built for documentation that changes with the product: one variable can carry the current version into every install command, a partial keeps shared setup in one file, and a flag can show a different example to different readers. Each of those features moves the code a reader copies further away from the text in the source file.
The source is not what readers copy. When a fence contains a variable tag, the published page shows the resolved value and the source shows the tag. A test that reads the source tests a string no reader ever sees, and a test that skips such fences leaves the most frequently copied commands untested.
Setup lives elsewhere. A partial that loads a package or defines a helper is part of every page that includes it. Read on its own, the including page uses names that appear to come from nowhere, and the partial looks like a page with one line of code.
Conditionals hide blocks. With an if tag, a page carries code for readers who will never see it under the current flags, and code that only some readers see. Both kinds can break; only the published combination is what a given reader copies.
Custom tabs are project code. Tabs in Markdoc are tags the project defines, so their meaning lives in configuration and components, not in the Markdown. A tool that does not load that configuration cannot know which blocks are alternatives.
Validation is not execution. Markdoc's validate step reports broken structure and attribute errors, which is valuable in CI, but it never runs the JavaScript or the shell commands. A renamed export passes validation, as the probe below shows.
Build the illustrative project
The files below are illustrative. The package name acme-units is illustrative and is not a published package. The probe used Markdoc 0.5.13, Node 24, Python 3.13 and engine 0.6.3.
Install Markdoc as a development dependency in the illustrative project.
npm install --save-dev @markdoc/markdoc
The package configuration exports the library by name from inside the package and defines a documentation-check task.
{
"name": "acme-units",
"version": "2.1.0",
"type": "commonjs",
"exports": "./lib/units.js",
"scripts": {
"check:docs": "node tools/check-docs.mjs"
},
"devDependencies": {
"@markdoc/markdoc": "^0.5.13"
}
}
The library converts bytes to whole kibibytes and formats that value. Its two exports are used by the documentation examples.
function toKiB(bytes) {
return Math.floor(bytes / 1024);
}
function formatSize(bytes) {
return `${toKiB(bytes)} KiB`;
}
module.exports = { toKiB, formatSize };
The illustrative partial loads those exports. When Markdoc expands it in a page, the setup appears before later examples.
Load the package first:
```js
const { toKiB, formatSize } = require("acme-units");
```
The install page uses custom tabs and a version variable in shell and JSON fences. These tags depend on the project’s configuration; a raw Markdown reader does not resolve them.
---
title: Install
---
# Install
{% tabs %}
{% tab label="npm" %}
```bash
npm install acme-units@{% $version %}
```
{% /tab %}
{% tab label="yarn" %}
```bash
yarn add acme-units@{% $version %}
```
{% /tab %}
{% /tabs %}
Pin the version in package.json:
```json
{ "dependencies": { "acme-units": "{% $version %}" } }
```
The usage page includes the partial, uses its setup in later JavaScript blocks, selects a branch with a flag and shows a literal tag in a fence with the process=false annotation.
---
title: Usage
---
# Usage
{% partial file="setup.md" /%}
```js
console.log(toKiB(2048));
```
{% if $flags.esm %}
```js
import { formatSize } from "acme-units";
console.log(formatSize(1536));
```
{% else /%}
```js
console.log(formatSize(1536));
```
{% /if %}
Show the tag itself instead of the version:
```markdown {% process=false %}
npm install acme-units@{% $version %}
```
The raw source contains more possible code paths than the page rendered with one flag setting. It also contains setup in a different file. Those are useful authoring features, but they make the source fences an incomplete representation of any one reader’s path.
Inspect a raw scan
This command plans a scan of the illustrative project. It does not execute the blocks by itself.
docsalive scan .
The plan found three pages and eight blocks: the install page, usage page and partial as a separate page. In the engine-driver probe with the network off, the install command was skipped for lack of network and the alternate package-manager command was skipped as a missing host tool. The JSON block parsed with the variable tag still present as a string. The partial passed on its own page.
On the usage page, two blocks relying on the partial failed as depends-on-context. The branch hidden by the false flag nevertheless ran and passed. The Markdown fence was skipped as non-executable. If a command containing a variable tag is run from raw source, the engine receives that literal text because it does not substitute the value; the probe’s install command was skipped, so it did not demonstrate such an execution.
A passing JSON parse establishes only that the source is parseable JSON under the engine’s check. It does not establish that Markdoc substituted the intended version or that the dependency value is correct for a release.
| Markdoc feature | What Markdoc does | What the engine does in 0.6.3 |
|---|---|---|
| Variable | Resolves it during transform | Leaves the raw tag text in the fence |
| Partial | Expands a registered parsed partial | Does not expand it; scans a partial file as its own page |
| If and else | Includes the active branch after transform | Plans blocks in every branch |
| Custom tabs | Renders the configured tags | Does not group these custom tab blocks as alternatives |
process=false |
Keeps fence content as plain text | Uses the first fence label; a Markdown fence is skipped as non-executable |
| Validation | Checks the tree against configuration | A scan is a separate execution and triage step |
.mdoc file |
Can be used by a Markdoc project | Is not selected as an engine page |
Validate and write a scan-ready copy
The following illustrative script validates top-level pages and writes their transformed fences to scan-docs/. It registers the tags, variables and partials used by this small project. It also combines JavaScript blocks in page order because the engine runs each JavaScript block in a separate Node process.
// Validate every Markdoc page, then write a scan-ready copy of its code
// fences with variables, partials and if/else already resolved.
import fs from "node:fs";
import path from "node:path";
import Markdoc from "@markdoc/markdoc";
const docs = "docs";
const out = "scan-docs";
const partialDir = path.join(docs, "partials");
const partials = {};
for (const name of fs.readdirSync(partialDir)) {
partials[name] = Markdoc.parse(fs.readFileSync(path.join(partialDir, name), "utf8"));
}
const config = {
tags: {
tabs: { render: "div", children: ["tag"] },
tab: { render: "section", attributes: { label: { type: String, required: true } } },
},
variables: { version: "2.1.0", flags: { esm: false } },
partials,
};
function fences(node, found = []) {
if (Array.isArray(node)) node.forEach((n) => fences(n, found));
else if (node && typeof node === "object") {
if (node.name === "pre") {
found.push({ lang: node.attributes["data-language"] || "text", code: node.children.join("") });
} else fences(node.children, found);
}
return found;
}
let errors = 0;
fs.rmSync(out, { recursive: true, force: true });
for (const file of fs.readdirSync(docs).filter((f) => f.endsWith(".md"))) {
const ast = Markdoc.parse(fs.readFileSync(path.join(docs, file), "utf8"));
for (const e of Markdoc.validate(ast, config)) {
if (e.error.level === "debug") continue;
errors++;
console.error(`${docs}/${file}:${(e.lines[0] ?? 0) + 1} ${e.error.level} ${e.error.id}: ${e.error.message}`);
}
const blocks = [];
for (const b of fences(Markdoc.transform(ast, config))) {
// The scan runs each js block in its own Node process, so keep one js
// block per page with the page's code in order.
const js = blocks.find((x) => x.lang === "js");
if (b.lang === "js" && js) js.code += "\n" + b.code;
else blocks.push(b);
}
const body = blocks.map((b) => "```" + b.lang + "\n" + b.code.replace(/\n$/, "") + "\n```\n").join("\n");
fs.mkdirSync(out, { recursive: true });
fs.writeFileSync(path.join(out, file), `# ${file}\n\n${body}`);
}
console.log(errors ? `${errors} problem(s)` : "no problems; scan-docs written");
process.exit(errors ? 1 : 0);
The script is a starting point with concrete limits:
- It uses one set of variable values and one flag setting per run. Run it once for each flag combination you publish.
- It reads only top-level
.mdfiles indocs/, not subfolders or.mdocfiles. - It registers only the tags and partial setup used here. Supply your site’s real tags, nodes, functions and variables; otherwise validation can report unknown tags or transform a different page.
- It merges all JavaScript blocks on a page in order. Review whether that models each published example and whether combining blocks changes their meaning.
- It writes tab variants as separate blocks without grouping them. Test the alternatives deliberately.
- Regenerate
scan-docs/in CI and do not edit it by hand. With--docs-dir scan-docs, the originaldocs/directory is not scanned.
Generate the copy and plan its scan with the following commands. For an execution run, arrange the package setup and execution options described in the CLI reference.
node tools/check-docs.mjs
docsalive scan . --docs-dir scan-docs
The script reported successful validation and wrote the copy.
no problems; scan-docs written
With the network off, the engine-driver probe read two pages and five blocks from the generated scope. The install command was skipped for network access, the alternate package-manager command was skipped as a missing tool, the JSON block parsed with the resolved version, the combined JavaScript block passed, and the Markdown block was non-executable.
The generated usage page makes the changed test boundary visible. The partial’s setup comes first and only the active else branch remains. The literal tag stays in the non-executable Markdown fence because the source requested plain treatment.
# usage.md
```js
const { toKiB, formatSize } = require("acme-units");
console.log(toKiB(2048));
console.log(formatSize(1536));
```
```markdown
npm install acme-units@{% $version %}
```
This copy is a test artifact, not a substitute for checking the rendered site. It contains fences, not the full reader experience. Check tab behavior, explanatory prose, links and presentation separately. The static site guide and Starlight guide discuss related site-level coverage.
Test structural and code failures separately
The first failure below is broken on purpose: the first closing tab tag was removed from the install page. Markdoc validation reported three structural problems and the script exited with status 1.
docs/install.md:7 critical missing-closing: Node 'tabs' is missing closing
docs/install.md:8 critical missing-closing: Node 'tab' is missing closing
docs/install.md:17 critical missing-opening: Node 'tag' is missing opening
3 problem(s)
Run validation in CI on each pull request so a broken tag is caught close to the edit. Pass the same configuration the site uses; a validation result based on a simplified configuration may not reflect the actual build.
The second failure is broken on purpose in a different way. The library export is renamed while the documentation remains unchanged.
-function formatSize(bytes) {
+function formatBytes(bytes) {
@@
-module.exports = { toKiB, formatSize };
+module.exports = { toKiB, formatBytes };
Markdoc validation still passed because it did not run the JavaScript. The scan of the transformed copy failed its combined JavaScript block as runtime-error, a finding needing review. A raw-source scan also produced an invalid-syntax finding for the branch that this flag setting did not publish. That latter result illustrates why selecting the rendered branch matters when interpreting a scan.
The transformed-copy failure was the following Node error:
TypeError: formatSize is not a function
Review the intended API and the page together. If the rename is intentional, update the partial and examples; if it is accidental, restore the export. Then regenerate the copy and rerun validation and execution. The JavaScript guide covers additional Node-oriented example checks.
Triage findings
| Finding | Likely cause | What to do |
|---|---|---|
| Missing-closing validation error | A tag was not closed as the configured structure requires | Fix the source and rerun validation with the site configuration |
| Valid source but runtime error | Validation did not execute the example | Test the transformed code against the intended package |
| Missing name in raw usage page | Setup lives in a partial the engine did not expand | Transform with registered partials before scanning |
| Failure in a hidden branch | Raw scan planned all branches | Generate and test each published flag combination |
| Literal version tag in a command | Raw scan did not substitute the variable | Use a transformed copy with the release value |
| JSON passes with a tag string | The raw string is valid JSON | Verify the transformed value and release configuration separately |
| A tab alternative was not tested as intended | Custom tabs were not grouped | Select and test each alternative deliberately |
No findings from an .mdoc page |
The engine did not select it as a page | Include it in your own generation workflow and verify the generated scope |
Where DocsAlive fits
Use Markdoc to validate and transform the source using the site’s real configuration. Use DocsAlive on a deliberately generated page set for supported executable blocks and categorized findings. The scan can isolate each page in a fresh container, but the example package must be available in that environment. The generated copy should preserve the setup a reader needs rather than silently supplying unrelated state.
For plain projects, the engine normally scans docs/ plus the root README when docs/ exists. A partials directory is not automatically excluded, which is why the raw probe treated the partial as a page. With the generated directory selected through --docs-dir, review both the generated pages and the root README in the scope. See framework support and findings for the engine’s current boundaries.
A scan does not replace a Markdoc build or a human review of the published page. It can help find broken supported examples after the transformation has selected the content readers receive. The Deno guide and Sybil guide show why runtime and parser semantics also need their own checks.
Markdoc documentation test checklist
[ ] Validate source with the same tags, nodes, functions, and variables as the site.
[ ] Register the partials used by each page.
[ ] Generate a scan-ready copy from Markdoc's transform in CI.
[ ] Include every published flag combination in the test plan.
[ ] Include nested pages and other file suffixes in your own generator as needed.
[ ] Review how combined JavaScript blocks model the reader's path.
[ ] Test custom tab alternatives deliberately.
[ ] Confirm variables resolve to the intended release values.
[ ] Scan the generated scope and review skipped blocks and findings.
[ ] Inspect the rendered site and its explanatory prose separately.
The sources we checked
These sources were read on November 15, 2026. Engine behavior was checked against engine 0.6.3 on the same day.
| Source | What it covers |
|---|---|
| Markdoc syntax | Tags, annotations, fences and comments |
| Markdoc tags | Built-in and custom tags |
| Markdoc nodes | Node configuration and fence attributes |
| Markdoc variables | Variable values and resolution |
| Markdoc partials | Registering and using partials |
| Markdoc validation | Validation errors and custom checks |
| Markdoc rendering | Parse, transform and render phases |
FAQ
Does Markdoc validation run code examples?
No. Validation checks the parsed document against configuration. Execute the relevant transformed examples separately to check whether their code works.
How does DocsAlive handle raw Markdoc?
Engine 0.6.3 does not substitute variables or expand partials. It scans partial files as separate pages, plans every if/else branch, does not group custom tabs, and does not select .mdoc files as pages. A scan-ready copy can resolve these features before scanning, within the generator's stated scope.
Why test transformed fences?
Variables, partials and conditions can make the published code differ from the raw source. Transforming with the site's configuration gives the test a closer representation of one published page.
Does the sample script cover every page and variant?
No. It reads top-level .md files and uses one set of values per run. Adapt it for your project, run each published flag combination, and test tab alternatives deliberately.
Why combine JavaScript blocks in the generated copy?
The engine runs each JavaScript block in its own Node process. Combining the illustrative page's blocks preserves the setup order for that probe, but you must check that combining blocks models your own examples correctly.
What does the process=false annotation do?
It makes Markdoc treat the fence content as plain text rather than resolving tags within it. That is useful when a page needs to show the tag itself.




