commonmark.json
TypeScript icon, indicating that this package has built-in type declarations

0.31.0 • Public • Published

commonmark.json

Build Downloads Size

CommonMark spec in JSON.

Contents

What is this?

This package exposes the CommonMark examples (tests) as plain objects.

When should I use this?

You can use this package when you are building a markdown parser.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install commonmark.json

In Deno with esm.sh:

import {commonmark} from 'https://esm.sh/commonmark.json@0.30'

In browsers with esm.sh:

<script type="module">
  import {commonmark} from 'https://esm.sh/commonmark.json@0.30?bundle'
</script>

Use

import {commonmark} from 'commonmark.json'

console.log(commonmark)

Yields:

[ { markdown: '\tfoo\tbaz\t\tbim\n',
    html: '<pre><code>foo\tbaz\t\tbim\n</code></pre>\n',
    section: 'Tabs' },
  { markdown: '  \tfoo\tbaz\t\tbim\n',
    html: '<pre><code>foo\tbaz\t\tbim\n</code></pre>\n',
    section: 'Tabs' },
  { markdown: '    a\ta\n    ὐ\ta\n',
    html: '<pre><code>a\ta\nὐ\ta\n</code></pre>\n',
    section: 'Tabs' },
  { markdown: '  - foo\n\n\tbar\n',
    html: '<ul>\n<li>\n<p>foo</p>\n<p>bar</p>\n</li>\n</ul>\n',
    section: 'Tabs' },
  { markdown: '- foo\n\n\t\tbar\n',
    html: '<ul>\n<li>\n<p>foo</p>\n<pre><code>  bar\n</code></pre>\n</li>\n</ul>\n',
    section: 'Tabs' },
  ... 622 more items ]

API

This package exports the identifiers commonmark. There is no default export.

commonmark

CommonMark test spec in JSON (Array<Example>).

Example

A test case (Object). Has the following fields:

  • markdown (string) — actual input markdown
  • html (string) — expected output HTML
  • section (string) — label of test group.

Types

This package is fully typed with TypeScript. It exports the additional type Example.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Security

This package is safe.

Contribute

Yes please! See How to Contribute to Open Source.

To generate new examples, run npm run generate to transform the spec at CommonMark’s HEAD to JSON.

Run it with a $VERSION to get JSON for a specific version, such as:

VERSION="0.27" node build

License

MIT © Titus Wormer

Package Sidebar

Install

npm i commonmark.json

Weekly Downloads

95

Version

0.31.0

License

MIT

Unpacked Size

100 kB

Total Files

5

Last publish

Collaborators

  • wooorm