11.0.0 • Published 8 months ago

commonform-commonmark v11.0.0

Weekly downloads
441
License
BlueOak-1.0.0
Repository
github
Last release
8 months ago

commonform-commonmark

convert CommonMark to and from Common Form

This package is the bridge between the way most people write legal terms for Common Form, and the internal data format that Common Form tools use to analyze, format, and share.

For a very short introduction to the syntax, see type.commonform.org.

This package includes a JavaScript module and command-line interface.

JavaScript

const commonmark = require('commonform-commonmark')
const assert = require('assert')

Parse CommonMark to Common Form.

assert.deepStrictEqual(
  commonmark.parse(
    [
      '# Purchase Price',
      'The purchase price is $10.'
    ].join('\n')
  ).form,
  {
    content: [
      {
        heading: 'Purchase Price',
        form: { content: ['The purchase price is $10.'] }
      }
    ]
  }
)

Extract fill-in-the-blank directions.

assert.deepStrictEqual(
  commonmark.parse(
    [
      '# Purchase Price',
      'The purchase price is `dollars`.'
    ].join('\n')
  ).directions,
  [
    {
      label: 'dollars',
      blank: ['content', 0, 'form', 'content', 1]
    }
  ]
)

Stringify Common Form to CommonMark.

assert.deepStrictEqual(
  commonmark.stringify({
    content: [
      'The ',
      { definition: 'Purchase Price' },
      ' is $10.'
    ]
  }),
  'The **Purchase Price** is $10.\n'
)

assert.deepStrictEqual(
  commonmark.stringify(
    {
      content: [
        'The ',
        { definition: 'Purchase Price' },
        ' is ',
        { blank: '' },
        '.'
      ]
    },
    [
      {
        value: '$10',
        blank: ['content', 3]
      }
    ]
  ),
  'The **Purchase Price** is $10.\n'
)

CLI

npx commonform-commonmark --help
10.0.0

8 months ago

9.0.0

9 months ago

11.0.0

8 months ago

8.0.0

2 years ago

7.0.0

2 years ago

6.0.0

4 years ago

5.3.0

4 years ago

5.2.1

4 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-pre.3

5 years ago

1.0.0-pre.2

5 years ago

1.0.0-pre.1

5 years ago