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.
npm install commonmark-specVerified import paths — ran on the pinned version, not inferred.
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.
If directly parsing `spec.txt`, update parsers to handle the new `example` block format introduced in 0.24. If using `spec_tests.py --dump-tests`, ensure your tooling expects the post-0.24 JSON structure. For `commonmark-spec` npm package users, ensure code correctly handles the `tests` array's JSON structure, especially when comparing against older data sets.
Review the CC-BY-SA 4.0 license terms and ensure compliance for your project, especially regarding attribution and share-alike conditions.
When programmatically accessing or filtering test cases, be aware of updated terminology in `section` names and other descriptive fields. Consult the `spec.txt` or the latest version of the tests for current naming conventions.
To import the raw `spec.txt` file in a web project, use a bundler-specific mechanism (e.g., `import specText from 'commonmark-spec/spec.txt?raw';` for Vite/Rollup). In Node.js, use `fs.readFileSync(require.resolve('commonmark-spec/spec.txt'), 'utf8')`.Use `const { tests } = require('commonmark-spec');` for CommonJS environments, or `import { tests } from 'commonmark-spec';` for ES Modules. Ensure your build configuration correctly handles ES modules if mixing syntax.Always add checks for array bounds (`i < tests.length`) and object property existence (e.g., `if (test && test.markdown)`) before accessing properties, especially if working with filtered or externally sourced test data.
No dependency data recorded yet.