CommonMark Specification and Test Cases

0.31.2 · active · verified Tue Apr 21

The `commonmark-spec` package provides the official CommonMark specification (`spec.txt`) and a comprehensive suite of over 500 conformance test cases in a machine-readable JSON format. It is a crucial resource for developers building or testing Markdown parsers and renderers that aim for CommonMark compatibility. This package primarily serves as a data source, not a Markdown processor itself; for implementations, refer to `commonmark.js` (JavaScript) or `cmark` (C). The current stable version is 0.31.2, released January 28, 2024. Releases generally occur with updates to the CommonMark specification, which includes clarifications, corrections, and sometimes minor syntactic adjustments. The package's core differentiator is its direct provision of the authoritative spec and its associated, extensive test suite, making it the definitive reference for CommonMark conformance testing.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the `tests` array and iterating through the first few CommonMark test cases to inspect their structure and content. It also shows filtering tests by section.

import { tests } from 'commonmark-spec';

console.log(`Total CommonMark test cases: ${tests.length}`);

// Display the first few test cases
for (let i = 0; i < Math.min(3, tests.length); i++) {
  const test = tests[i];
  console.log(`\n--- Test Case ${test.number} (${test.section}) ---\n`);
  console.log('Markdown Input:\n' + test.markdown.trim());
  console.log('Expected HTML Output:\n' + test.html.trim());
}

// Example of how to filter tests for a specific section
const emphasisTests = tests.filter(test => test.section === 'Emphasis and strong emphasis');
console.log(`\nNumber of emphasis tests: ${emphasisTests.length}`);

view raw JSON →