Registry / testing / commonmark.json

commonmark.json

JSON →
library0.31.0jsnpmunverified

commonmark.json provides the complete suite of examples and test cases specified by the CommonMark standard, formatted as a readily consumable JSON array. Each entry in the array represents a single test case, including the input Markdown, the expected HTML output, and the section of the CommonMark specification it pertains to. This package is currently on stable version 0.31.0 and is updated periodically, typically when the official CommonMark specification is revised or regenerated, ensuring alignment with the latest standard. Its primary utility lies in serving as a robust dataset for developers building or validating Markdown parsers, allowing them to systematically test their implementations against the authoritative CommonMark examples rather than providing parsing functionality itself. It is designed to be a lightweight, data-only dependency.

npm install commonmark.json
INSTALL
IMPORT
SIG · COMMONMARK.JSON
C
commonmark.json
testingjavascriptv0.31.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

commonmark
✓ import { commonmark } from 'commonmark.json';
✗ const commonmark = require('commonmark.json');
The package is ESM-only since v0.30.0; CommonJS `require` is not supported. This import provides the full array of test cases.
Example
✓ import type { Example } from 'commonmark.json';
This is the TypeScript type definition for a single CommonMark test case object, useful for type safety when working with the `commonmark` array.

Loads and logs various CommonMark test cases, demonstrating how to access, filter, and iterate through the specification data for testing purposes.

import { commonmark, type Example } from 'commonmark.json'; // Log the total number of CommonMark test cases available. console.log(`Total CommonMark examples: ${commonmark.length} test cases.`); // Access and log the first example's markdown and expected HTML. const firstExample: Example = commonmark[0]; console.log('\n--- First Example ---'); console.log('Markdown Input:\n', firstExample.markdown.trim()); console.log('Expected HTML Output:\n', firstExample.html.trim()); console.log('Section:', firstExample.section); // Find a specific example by section (e.g., a paragraph example) and log it. const paragraphExample = commonmark.find( (example) => example.section === 'Paragraphs' && example.markdown.includes('hello') ); if (paragraphExample) { console.log('\n--- Found Paragraph Example (filtered) ---'); console.log('Markdown Input:\n', paragraphExample.markdown.trim()); console.log('Expected HTML Output:\n', paragraphExample.html.trim()); } else { console.log('\nCould not find a specific paragraph example matching the criteria.'); } // Demonstrate iterating through the first few examples. console.log('\n--- Iterating First 3 Examples ---'); for (let i = 0; i < Math.min(3, commonmark.length); i++) { const example = commonmark[i]; console.log(`\nExample ${i + 1} (Section: ${example.section}):`); console.log(' Markdown (first line):', example.markdown.split('\n')[0].trim() + '...'); console.log(' HTML (first line):', example.html.split('\n')[0].trim() + '...'); }
Debug
Known issues
breakingThe `commonmark.json` package transitioned to be ESM-only. CommonJS `require()` statements are no longer supported for direct import.
fix
Update your project to use ECMAScript Modules (`import`) or configure your build system/Node.js environment (`"type": "module"` in `package.json`) to handle ESM. For older CommonJS projects, dynamic `import()` might be an option.
affects: >=0.30.0
gotchaThis package exports raw data (an array of CommonMark examples) directly, not a function or a parser. It serves as a static dataset for testing, not an executable library.
fix
Access the `commonmark` export as an array to iterate over the test cases (`commonmark.map(...)`, `commonmark[0].markdown`). Do not attempt to call `commonmark` as a function.
affects: >=0.1.0
gotchaThe `commonmark` array contains over 600 test cases, leading to a noticeable impact on bundle size (multiple KB gzipped) and potentially Node.js startup time if imported directly into every module, especially for browser applications.
fix
If bundle size is a critical concern, consider using dynamic `import()` to load the data only when strictly necessary. For most testing scenarios, direct import is acceptable.
affects: *
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
You are attempting to use an ESM `import` statement in a CommonJS context after the package became ESM-only.
fix
Ensure your Node.js project or build configuration is set up for ESM. This typically involves adding `"type": "module"` to your `package.json` file or renaming your file to `.mjs`.
TypeError: commonmark.map is not a function
This error is unlikely, but if `commonmark` was imported incorrectly (e.g., as a default export) or if you tried to call it like a function, you might see this. `commonmark` is an array.
fix
Ensure you are using a named import `import { commonmark } from 'commonmark.json'` and interacting with `commonmark` as an array (e.g., `commonmark.length`, `commonmark[0]`, `commonmark.forEach(...)`).
Upgrade
Version history
0.31.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
commonmark.json — npm install commonmark.json · libregistry