commonform-commonmark
v11.0.0
Published
convert CommonMark to and from Common Form
Downloads
7
Readme
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