{"id":12981,"library":"commonmark.json","title":"CommonMark Specification Tests JSON","description":"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.","status":"active","version":"0.31.0","language":"javascript","source_language":"en","source_url":"https://github.com/wooorm/commonmark.json","tags":["javascript","markdown","commonmark","spec","test","json","typescript"],"install":[{"cmd":"npm install commonmark.json","lang":"bash","label":"npm"},{"cmd":"yarn add commonmark.json","lang":"bash","label":"yarn"},{"cmd":"pnpm add commonmark.json","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v0.30.0; CommonJS `require` is not supported. This import provides the full array of test cases.","wrong":"const commonmark = require('commonmark.json');","symbol":"commonmark","correct":"import { commonmark } from 'commonmark.json';"},{"note":"This is the TypeScript type definition for a single CommonMark test case object, useful for type safety when working with the `commonmark` array.","symbol":"Example","correct":"import type { Example } from 'commonmark.json';"}],"quickstart":{"code":"import { commonmark, type Example } from 'commonmark.json';\n\n// Log the total number of CommonMark test cases available.\nconsole.log(`Total CommonMark examples: ${commonmark.length} test cases.`);\n\n// Access and log the first example's markdown and expected HTML.\nconst firstExample: Example = commonmark[0];\nconsole.log('\\n--- First Example ---');\nconsole.log('Markdown Input:\\n', firstExample.markdown.trim());\nconsole.log('Expected HTML Output:\\n', firstExample.html.trim());\nconsole.log('Section:', firstExample.section);\n\n// Find a specific example by section (e.g., a paragraph example) and log it.\nconst paragraphExample = commonmark.find(\n  (example) => example.section === 'Paragraphs' && example.markdown.includes('hello')\n);\n\nif (paragraphExample) {\n  console.log('\\n--- Found Paragraph Example (filtered) ---');\n  console.log('Markdown Input:\\n', paragraphExample.markdown.trim());\n  console.log('Expected HTML Output:\\n', paragraphExample.html.trim());\n} else {\n  console.log('\\nCould not find a specific paragraph example matching the criteria.');\n}\n\n// Demonstrate iterating through the first few examples.\nconsole.log('\\n--- Iterating First 3 Examples ---');\nfor (let i = 0; i < Math.min(3, commonmark.length); i++) {\n  const example = commonmark[i];\n  console.log(`\\nExample ${i + 1} (Section: ${example.section}):`);\n  console.log('  Markdown (first line):', example.markdown.split('\\n')[0].trim() + '...');\n  console.log('  HTML (first line):', example.html.split('\\n')[0].trim() + '...');\n}","lang":"typescript","description":"Loads and logs various CommonMark test cases, demonstrating how to access, filter, and iterate through the specification data for testing purposes."},"warnings":[{"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.","message":"The `commonmark.json` package transitioned to be ESM-only. CommonJS `require()` statements are no longer supported for direct import.","severity":"breaking","affected_versions":">=0.30.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"You are attempting to use an ESM `import` statement in a CommonJS context after the package became ESM-only.","error":"SyntaxError: Cannot use import statement outside a module"},{"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(...)`).","cause":"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.","error":"TypeError: commonmark.map is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}