diff --git a/package.json b/package.json index f5b2426..0fe446b 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "uvu": "^0.5.0" }, "devDependencies": { - "@types/tape": "^4.0.0", + "@types/node": "^18.0.0", "c8": "^7.0.0", "html-void-elements": "^2.0.0", "micromark": "^3.0.0", diff --git a/test/index.js b/test/index.js index dcfa5f5..2880738 100644 --- a/test/index.js +++ b/test/index.js @@ -4,1161 +4,1160 @@ * @typedef {import('../dev/index.js').Handle} Handle */ -import test from 'tape' +import assert from 'node:assert/strict' +import test from 'node:test' import {micromark} from 'micromark' import {htmlVoidElements} from 'html-void-elements' import {directive as syntax, directiveHtml as html} from '../dev/index.js' const own = {}.hasOwnProperty -test('micromark-extension-directive (syntax)', (t) => { - t.test('text', (t) => { - t.equal( - micromark('\\:a', options()), - '
:a
', - 'should support an escaped colon which would otherwise be a directive' - ) - - t.equal( - micromark('\\::a', options()), - ':
', - 'should support a directive after an escaped colon' - ) - - t.equal( - micromark('a ::b', options()), - 'a ::b
', - 'should not support a directive after a colon' - ) - - t.equal( - micromark(':', options()), - ':
', - 'should not support a colon not followed by an alpha' - ) - - t.equal( - micromark(':a', options()), - '', - 'should support a colon followed by an alpha' - ) - - t.equal( - micromark(':9', options()), - ':9
', - 'should not support a colon followed by a digit' - ) - - t.equal( - micromark(':-', options()), - ':-
', - 'should not support a colon followed by a dash' - ) - - t.equal( - micromark(':_', options()), - ':_
', - 'should not support a colon followed by an underscore' - ) - - t.equal( - micromark(':a9', options()), - '', - 'should support a digit in a name' - ) - - t.equal( - micromark(':a-b', options()), - '', - 'should support a dash in a name' - ) - - t.equal( - micromark(':a-', options()), - ':a-
', - 'should *not* support a dash at the end of a name' - ) - - t.equal( - micromark(':a_b', options()), - '', - 'should support an underscore in a name' - ) - - t.equal( - micromark(':a_', options()), - ':a_
', - 'should *not* support an underscore at the end of a name' - ) - - t.equal( - micromark(':a:', options()), - ':a:
', - 'should *not* support a colon right after a name' - ) - - t.equal( - micromark(':+1:', options()), - ':+1:
', - 'should not interfere w/ gemoji (1)' - ) - - t.equal( - micromark(':heart:', options()), - ':heart:
', - 'should not interfere w/ gemoji (2)' - ) - - t.equal( - micromark(':call_me_hand:', options()), - ':call_me_hand:
', - 'should not interfere w/ gemoji (3)' - ) - - t.equal( - micromark('_:directive_', options()), - ':directive
', - 'should not interfere w/ emphasis (`_`)' - ) - - t.equal( - micromark(':a[', options()), - '[
', - 'should support a name followed by an unclosed `[`' - ) - - t.equal( - micromark(':a{', options()), - '{
', - 'should support a name followed by an unclosed `{`' - ) - - t.equal( - micromark(':a[b', options()), - '[b
', - 'should support a name followed by an unclosed `[` w/ content' - ) - - t.equal( - micromark(':a{b', options()), - '{b
', - 'should support a name followed by an unclosed `{` w/ content' - ) - - t.equal( - micromark(':a[]', options()), - '', - 'should support an empty label' - ) - - t.equal( - micromark(':a[ \t]', options()), - '', - 'should support a whitespace only label' - ) - - t.equal( - micromark(':a[\n]', options()), - '', - 'should support an eol in an label' - ) - - t.equal( - micromark(':a[a b c]asd', options()), - 'asd
', - 'should support content in an label' - ) - - t.equal( - micromark(':a[a *b* c]asd', options()), - 'asd
', - 'should support markdown in an label' - ) - - t.equal( - micromark('a :b[c :d[e] f] g', options()), - 'a g
', - 'should support a directive in an label' - ) - - t.equal( - micromark(':a[]asd', options()), - 'asd
', - 'should support content after a label' - ) - - t.equal( - micromark(':a{}', options()), - '', - 'should support empty attributes' - ) - - t.equal( - micromark(':a{ \t}', options()), - '', - 'should support whitespace only attributes' - ) - - t.equal( - micromark(':a{\n}', options()), - '', - 'should support an eol in attributes' - ) - - t.equal( - micromark(':a{a b c}', options()), - '', - 'should support attributes w/o values' - ) - - t.equal( - micromark(':a{a=b c=d}', options()), - '', - 'should support attributes w/ unquoted values' - ) - - t.equal( - micromark(':a{.a .b}', options()), - '', - 'should support attributes w/ class shortcut' - ) - - t.equal( - micromark(':a{.a.b}', options()), - '', - 'should support attributes w/ class shortcut w/o whitespace between' - ) - - t.equal( - micromark(':a{#a #b}', options()), - '', - 'should support attributes w/ id shortcut' - ) - - t.equal( - micromark(':a{#a#b}', options()), - '', - 'should support attributes w/ id shortcut w/o whitespace between' - ) - - t.equal( - micromark(':a{#a.b.c#d e f=g #h.i.j}', options()), - '', - 'should support attributes w/ shortcuts combined w/ other attributes' - ) - - t.equal( - micromark(':a{..b}', options()), - '{..b}
', - 'should not support an empty shortcut (`.`)' - ) - - t.equal( - micromark(':a{.#b}', options()), - '{.#b}
', - 'should not support an empty shortcut (`#`)' - ) - - t.equal( - micromark(':a{.}', options()), - '{.}
', - 'should not support an empty shortcut (`}`)' - ) - - t.equal( - micromark(':a{.a=b}', options()), - '{.a=b}
', - 'should not support certain characters in shortcuts (`=`)' - ) - - t.equal( - micromark(':a{.a"b}', options()), - '{.a"b}
', - 'should not support certain characters in shortcuts (`"`)' - ) - - t.equal( - micromark(':a{.a{.a<b}', - 'should not support certain characters in shortcuts (`<`)' - ) - - t.equal( - micromark(':a{.ađź’šb}', options()), - '', - 'should support most characters in shortcuts' - ) - - t.equal( - micromark(':a{_}', options()), - '', - 'should support an underscore in attribute names' - ) - - t.equal( - micromark(':a{xml:lang}', options()), - '', - 'should support a colon in attribute names' - ) - - t.equal( - micromark(':a{a="b" c="d e f"}', options()), - '', - 'should support double quoted attributes' - ) - - t.equal( - micromark(":a{a='b' c='d e f'}", options()), - '', - 'should support single quoted attributes' - ) - - t.equal( - micromark(':a{a = b c\t=\t\'d\' f =\r"g"}', options()), - '', - 'should support whitespace around initializers' - ) - - t.equal( - micromark(':a{b==}', options()), - '{b==}
', - 'should not support `=` to start an unquoted attribute value' - ) - - t.equal( - micromark(':a{b=}', options()), - '{b=}
', - 'should not support a missing attribute value after `=`' - ) - - t.equal( - micromark(":a{b=c'}", options()), - "{b=c'}
", - 'should not support an apostrophe in an unquoted attribute value' - ) - - t.equal( - micromark(':a{b=c`}', options()), - '{b=c`}
', - 'should not support a grave accent in an unquoted attribute value' - ) - - t.equal( - micromark(':a{b=ađź’šb}', options()), - '', - 'should support most other characters in unquoted attribute values' - ) - - t.equal( - micromark(':a{b="c', options()), - '{b="c
', - 'should not support an EOF in a quoted attribute value' - ) - - t.equal( - micromark(':a{b="ađź’šb"}', options()), - '', - 'should support most other characters in quoted attribute values' - ) - - t.equal( - micromark(':a{b="\nc\r d"}', options()), - '', - 'should support EOLs in quoted attribute values' - ) - - t.equal( - micromark(':a{b="c"', options()), - '{b="c"
', - 'should not support an EOF after a quoted attribute value' - ) - - t.end() - }) - - t.test('leaf', (t) => { - t.equal(micromark('::b', options()), '', 'should support a directive') - - t.equal( - micromark(':', options()), - ':
', - 'should not support one colon' - ) - - t.equal( - micromark('::', options()), - '::
', - 'should not support two colons not followed by an alpha' - ) - - t.equal( - micromark('::a', options()), - '', - 'should support two colons followed by an alpha' - ) - - t.equal( - micromark('::9', options()), - '::9
', - 'should not support two colons followed by a digit' - ) - - t.equal( - micromark('::-', options()), - '::-
', - 'should not support two colons followed by a dash' - ) - - t.equal( - micromark('::a9', options()), - '', - 'should support a digit in a name' - ) - - t.equal( - micromark('::a-b', options()), - '', - 'should support a dash in a name' - ) - - t.equal( - micromark('::a[', options()), - '::a[
', - 'should not support a name followed by an unclosed `[`' - ) - - t.equal( - micromark('::a{', options()), - '::a{
', - 'should not support a name followed by an unclosed `{`' - ) - - t.equal( - micromark('::a[b', options()), - '::a[b
', - 'should not support a name followed by an unclosed `[` w/ content' - ) - - t.equal( - micromark('::a{b', options()), - '::a{b
', - 'should not support a name followed by an unclosed `{` w/ content' - ) - - t.equal(micromark('::a[]', options()), '', 'should support an empty label') - - t.equal( - micromark('::a[ \t]', options()), - '', - 'should support a whitespace only label' - ) - - t.equal( - micromark('::a[\n]', options()), - '::a[\n]
', - 'should not support an eol in an label' - ) - - t.equal( - micromark('::a[a b c]', options()), - '', - 'should support content in an label' - ) - - t.equal( - micromark('::a[a *b* c]', options()), - '', - 'should support markdown in an label' - ) - - t.equal( - micromark('::a[]asd', options()), - '::a[]asd
', - 'should not support content after a label' - ) - - t.equal( - micromark('::a{}', options()), - '', - 'should support empty attributes' - ) - - t.equal( - micromark('::a{ \t}', options()), - '', - 'should support whitespace only attributes' - ) - - t.equal( - micromark('::a{\n}', options()), - '::a{\n}
', - 'should not support an eol in attributes' - ) - - t.equal( - micromark('::a{a b c}', options()), - '', - 'should support attributes w/o values' - ) - - t.equal( - micromark('::a{a=b c=d}', options()), - '', - 'should support attributes w/ unquoted values' - ) - - t.equal( - micromark('::a{.a .b}', options()), - '', - 'should support attributes w/ class shortcut' - ) - - t.equal( - micromark('::a{#a #b}', options()), - '', - 'should support attributes w/ id shortcut' - ) - - t.equal( - micromark('::a{.ađź’šb}', options()), - '', - 'should support most characters in shortcuts' - ) - - t.equal( - micromark('::a{a="b" c="d e f"}', options()), - '', - 'should support double quoted attributes' - ) - - t.equal( - micromark("::a{a='b' c='d e f'}", options()), - '', - 'should support single quoted attributes' - ) - - t.equal( - micromark("::a{a = b c\t=\t'd'}", options()), - '', - 'should support whitespace around initializers' - ) - - t.equal( - micromark('::a{f =\rg}', options()), - '::a{f =\rg}
', - 'should not support EOLs around initializers' - ) - - t.equal( - micromark('::a{b==}', options()), - '::a{b==}
', - 'should not support `=` to start an unquoted attribute value' - ) - - t.equal( - micromark('::a{b=ađź’šb}', options()), - '', - 'should support most other characters in unquoted attribute values' - ) - - t.equal( - micromark('::a{b="c', options()), - '::a{b="c
', - 'should not support an EOF in a quoted attribute value' - ) - - t.equal( - micromark('::a{b="ađź’šb"}', options()), - '', - 'should support most other characters in quoted attribute values' - ) - - t.equal( - micromark('::a{b="\nc\r d"}', options()), - '::a{b="\nc\rd"}
', - 'should not support EOLs in quoted attribute values' - ) - - t.equal( - micromark('::a{b="c"', options()), - '::a{b="c"
', - 'should not support an EOF after a quoted attribute value' - ) - - t.equal( - micromark('::a{b=c} \t ', options()), - '', - 'should support whitespace after directives' - ) - - t.equal( - micromark('::a{b=c}\n>a', options()), - '\n', - 'should support a block quote after a leaf' - ) - - t.equal( - micromark('::a{b=c}\n```js\na', options()), - 'a
\n
a\n
\n',
- 'should support code (fenced) after a leaf'
- )
-
- t.equal(
- micromark('::a{b=c}\n a', options()),
- 'a\n
',
- 'should support code (indented) after a leaf'
- )
-
- t.equal(
- micromark('::a{b=c}\n[a]: b', options()),
- '',
- 'should support a definition after a leaf'
- )
-
- t.equal(
- micromark('::a{b=c}\n# a', options()),
- 'a
', - 'should support a paragraph after a leaf' - ) - - t.equal( - micromark('::a{b=c}\n***', options()), - '\n\n', - 'should support a block quote before a leaf' - ) - - t.equal( - micromark('```js\na\n```\n::a{b=c}', options()), - 'a
\n
a\n
\n',
- 'should support code (fenced) before a leaf'
- )
-
- t.equal(
- micromark(' a\n::a{b=c}', options()),
- 'a\n
\n',
- 'should support code (indented) before a leaf'
- )
-
- t.equal(
- micromark('[a]: b\n::a{b=c}', options()),
- '',
- 'should support a definition before a leaf'
- )
-
- t.equal(
- micromark('# a\n::a{b=c}', options()),
- 'a
\n', - 'should support a paragraph before a leaf' - ) - - t.equal( - micromark('***\n::a{b=c}', options()), - '\n\n
b
', - 'should not support lazyness (1)' - ) - - t.equal( - micromark('> a\n::b', options({'*': h})), - '\n\n', - 'should not support lazyness (2)' - ) - - t.end() - }) - - t.test('container', (t) => { - t.equal(micromark(':::b', options()), '', 'should support a directive') - - t.equal( - micromark(':', options()), - 'a
\n
:
', - 'should not support one colon' - ) - - t.equal( - micromark('::', options()), - '::
', - 'should not support two colons not followed by an alpha' - ) - - t.equal( - micromark(':::', options()), - ':::
', - 'should not support three colons not followed by an alpha' - ) - - t.equal( - micromark(':::a', options()), - '', - 'should support three colons followed by an alpha' - ) - - t.equal( - micromark(':::9', options()), - ':::9
', - 'should not support three colons followed by a digit' - ) - - t.equal( - micromark(':::-', options()), - ':::-
', - 'should not support three colons followed by a dash' - ) - - t.equal( - micromark(':::a9', options()), - '', - 'should support a digit in a name' - ) - - t.equal( - micromark(':::a-b', options()), - '', - 'should support a dash in a name' - ) - - t.equal( - micromark(':::a[', options()), - ':::a[
', - 'should not support a name followed by an unclosed `[`' - ) - - t.equal( - micromark(':::a{', options()), - ':::a{
', - 'should not support a name followed by an unclosed `{`' - ) - - t.equal( - micromark(':::a[b', options()), - ':::a[b
', - 'should not support a name followed by an unclosed `[` w/ content' - ) - - t.equal( - micromark(':::a{b', options()), - ':::a{b
', - 'should not support a name followed by an unclosed `{` w/ content' - ) - - t.equal(micromark(':::a[]', options()), '', 'should support an empty label') - - t.equal( - micromark(':::a[ \t]', options()), - '', - 'should support a whitespace only label' - ) - - t.equal( - micromark(':::a[\n]', options()), - ':::a[\n]
', - 'should not support an eol in an label' - ) - - t.equal( - micromark(':::a[a b c]', options()), - '', - 'should support content in an label' - ) - - t.equal( - micromark(':::a[a *b* c]', options()), - '', - 'should support markdown in an label' - ) - - t.equal( - micromark(':::a[]asd', options()), - ':::a[]asd
', - 'should not support content after a label' - ) - - t.equal( - micromark(':::a{}', options()), - '', - 'should support empty attributes' - ) - - t.equal( - micromark(':::a{ \t}', options()), - '', - 'should support whitespace only attributes' - ) - - t.equal( - micromark(':::a{\n}', options()), - ':::a{\n}
', - 'should not support an eol in attributes' - ) - - t.equal( - micromark(':::a{a b c}', options()), - '', - 'should support attributes' - ) - - t.equal( - micromark(':::a{f =\rg}', options()), - ':::a{f =\rg}
', - 'should not support EOLs around initializers' - ) - - t.equal( - micromark(':::a{b="c', options()), - ':::a{b="c
', - 'should not support an EOF in a quoted attribute value' - ) - - t.equal( - micromark(':::a{b="\nc\r d"}', options()), - ':::a{b="\nc\rd"}
', - 'should not support EOLs in quoted attribute values' - ) - - t.equal( - micromark(':::a{b="c"', options()), - ':::a{b="c"
', - 'should not support an EOF after a quoted attribute value' - ) - - t.equal( - micromark(':::a{b=c} \t ', options()), - '', - 'should support whitespace after directives' - ) - - t.equal( - micromark(':::a\n', options()), - '', - 'should support no closing fence' - ) - - t.equal( - micromark(':::a\n:::', options()), - '', - 'should support an immediate closing fence' - ) - - t.equal( - micromark(':::a\n:::\nb', options()), - 'b
', - 'should support content after a closing fence' - ) - - t.equal( - micromark(':::a\n::\nb', options()), - '', - 'should not close w/ a “closing” fence of two colons' - ) - - t.equal( - micromark(':::a\n::::\nb', options()), - 'b
', - 'should close w/ a closing fence of more colons' - ) - - t.equal( - micromark('::::a\n::::\nb', options()), - 'b
', - 'should support more opening colons' - ) - - t.equal( - micromark(':::::a\n::::\nb', options()), - '', - 'should not close w/ a “closing” fence of less colons than the opening' - ) - - t.equal( - micromark(':::a\n::: \t\nc', options()), - 'c
', - 'should close w/ a closing fence followed by white space' - ) - - t.equal( - micromark(':::a\n::: b\nc', options()), - '', - 'should not close w/ a “closing” fence followed by other characters' - ) - - t.equal( - micromark(':::a\n :::\nc', options()), - 'c
', - 'should close w/ an indented closing fence' - ) - - t.equal( - micromark(':::a\n\t:::\nc', options()), - '', - 'should not close w/ when the “closing” fence is indented at a tab size' - ) - - t.equal( - micromark(':::a\n :::\nc', options()), - '', - 'should not close w/ when the “closing” fence is indented more than a tab size' - ) - - t.equal( - micromark(':::a\n\n \n\ta', options()), - '', - 'should support blank lines in content' - ) - - t.equal( - micromark(':::a\n\ta\n', options()), - '', - 'should support an EOL EOF' - ) - - t.equal( - micromark(' :::a\n b\n :::\nc', options()), - 'c
', - 'should support an indented directive' - ) - - t.equal( - micromark(' :::a\n\t:::\nc', options()), - '', - 'should still not close an indented directive when the “closing” fence is indented a tab size' - ) - - t.equal( - micromark(':::a\n:::\n>a', options()), - '\n', - 'should support a block quote after a container' - ) - - t.equal( - micromark(':::a\n:::\n```js\na', options()), - 'a
\n
a\n
\n',
- 'should support code (fenced) after a container'
- )
-
- t.equal(
- micromark(':::a\n:::\n a', options()),
- 'a\n
',
- 'should support code (indented) after a container'
- )
-
- t.equal(
- micromark(':::a\n:::\n[a]: b', options()),
- '',
- 'should support a definition after a container'
- )
-
- t.equal(
- micromark(':::a\n:::\n# a', options()),
- 'a
', - 'should support a paragraph after a container' - ) - - t.equal( - micromark(':::a\n:::\n***', options()), - '\n\n', - 'should support a block quote before a container' - ) - - t.equal( - micromark('```js\na\n```\n:::a\nb', options()), - 'a
\n
a\n
\n',
- 'should support code (fenced) before a container'
- )
-
- t.equal(
- micromark(' a\n:::a\nb', options()),
- 'a\n
\n',
- 'should support code (indented) before a container'
- )
-
- t.equal(
- micromark('[a]: b\n:::a\nb', options()),
- '',
- 'should support a definition before a container'
- )
-
- t.equal(
- micromark('# a\n:::a\nb', options()),
- 'a
\n', - 'should support a paragraph before a container' - ) - - t.equal( - micromark('***\n:::a\nb', options()), - '\n\nb
\n
\n\nb
\n
\n\n
b
', - 'should not support lazyness (1)' - ) - - t.equal( - micromark('> :::a\n> b\nc', options({'*': h})), - '\n\nb
\n\n
c
', - 'should not support lazyness (2)' - ) - - t.equal( - micromark('> a\n:::b', options({'*': h})), - '\n\n', - 'should not support lazyness (3)' - ) - - t.equal( - micromark('> :::a\n:::', options({'*': h})), - 'a
\n
\n\n
:::
', - 'should not support lazyness (4)' - ) - - t.end() - }) - - t.end() +test('micromark-extension-directive (syntax, text)', () => { + assert.equal( + micromark('\\:a', options()), + ':a
', + 'should support an escaped colon which would otherwise be a directive' + ) + + assert.equal( + micromark('\\::a', options()), + ':
', + 'should support a directive after an escaped colon' + ) + + assert.equal( + micromark('a ::b', options()), + 'a ::b
', + 'should not support a directive after a colon' + ) + + assert.equal( + micromark(':', options()), + ':
', + 'should not support a colon not followed by an alpha' + ) + + assert.equal( + micromark(':a', options()), + '', + 'should support a colon followed by an alpha' + ) + + assert.equal( + micromark(':9', options()), + ':9
', + 'should not support a colon followed by a digit' + ) + + assert.equal( + micromark(':-', options()), + ':-
', + 'should not support a colon followed by a dash' + ) + + assert.equal( + micromark(':_', options()), + ':_
', + 'should not support a colon followed by an underscore' + ) + + assert.equal( + micromark(':a9', options()), + '', + 'should support a digit in a name' + ) + + assert.equal( + micromark(':a-b', options()), + '', + 'should support a dash in a name' + ) + + assert.equal( + micromark(':a-', options()), + ':a-
', + 'should *not* support a dash at the end of a name' + ) + + assert.equal( + micromark(':a_b', options()), + '', + 'should support an underscore in a name' + ) + + assert.equal( + micromark(':a_', options()), + ':a_
', + 'should *not* support an underscore at the end of a name' + ) + + assert.equal( + micromark(':a:', options()), + ':a:
', + 'should *not* support a colon right after a name' + ) + + assert.equal( + micromark(':+1:', options()), + ':+1:
', + 'should not interfere w/ gemoji (1)' + ) + + assert.equal( + micromark(':heart:', options()), + ':heart:
', + 'should not interfere w/ gemoji (2)' + ) + + assert.equal( + micromark(':call_me_hand:', options()), + ':call_me_hand:
', + 'should not interfere w/ gemoji (3)' + ) + + assert.equal( + micromark('_:directive_', options()), + ':directive
', + 'should not interfere w/ emphasis (`_`)' + ) + + assert.equal( + micromark(':a[', options()), + '[
', + 'should support a name followed by an unclosed `[`' + ) + + assert.equal( + micromark(':a{', options()), + '{
', + 'should support a name followed by an unclosed `{`' + ) + + assert.equal( + micromark(':a[b', options()), + '[b
', + 'should support a name followed by an unclosed `[` w/ content' + ) + + assert.equal( + micromark(':a{b', options()), + '{b
', + 'should support a name followed by an unclosed `{` w/ content' + ) + + assert.equal( + micromark(':a[]', options()), + '', + 'should support an empty label' + ) + + assert.equal( + micromark(':a[ \t]', options()), + '', + 'should support a whitespace only label' + ) + + assert.equal( + micromark(':a[\n]', options()), + '', + 'should support an eol in an label' + ) + + assert.equal( + micromark(':a[a b c]asd', options()), + 'asd
', + 'should support content in an label' + ) + + assert.equal( + micromark(':a[a *b* c]asd', options()), + 'asd
', + 'should support markdown in an label' + ) + + assert.equal( + micromark('a :b[c :d[e] f] g', options()), + 'a g
', + 'should support a directive in an label' + ) + + assert.equal( + micromark(':a[]asd', options()), + 'asd
', + 'should support content after a label' + ) + + assert.equal( + micromark(':a{}', options()), + '', + 'should support empty attributes' + ) + + assert.equal( + micromark(':a{ \t}', options()), + '', + 'should support whitespace only attributes' + ) + + assert.equal( + micromark(':a{\n}', options()), + '', + 'should support an eol in attributes' + ) + + assert.equal( + micromark(':a{a b c}', options()), + '', + 'should support attributes w/o values' + ) + + assert.equal( + micromark(':a{a=b c=d}', options()), + '', + 'should support attributes w/ unquoted values' + ) + + assert.equal( + micromark(':a{.a .b}', options()), + '', + 'should support attributes w/ class shortcut' + ) + + assert.equal( + micromark(':a{.a.b}', options()), + '', + 'should support attributes w/ class shortcut w/o whitespace between' + ) + + assert.equal( + micromark(':a{#a #b}', options()), + '', + 'should support attributes w/ id shortcut' + ) + + assert.equal( + micromark(':a{#a#b}', options()), + '', + 'should support attributes w/ id shortcut w/o whitespace between' + ) + + assert.equal( + micromark(':a{#a.b.c#d e f=g #h.i.j}', options()), + '', + 'should support attributes w/ shortcuts combined w/ other attributes' + ) + + assert.equal( + micromark(':a{..b}', options()), + '{..b}
', + 'should not support an empty shortcut (`.`)' + ) + + assert.equal( + micromark(':a{.#b}', options()), + '{.#b}
', + 'should not support an empty shortcut (`#`)' + ) + + assert.equal( + micromark(':a{.}', options()), + '{.}
', + 'should not support an empty shortcut (`}`)' + ) + + assert.equal( + micromark(':a{.a=b}', options()), + '{.a=b}
', + 'should not support certain characters in shortcuts (`=`)' + ) + + assert.equal( + micromark(':a{.a"b}', options()), + '{.a"b}
', + 'should not support certain characters in shortcuts (`"`)' + ) + + assert.equal( + micromark(':a{.a{.a<b}', + 'should not support certain characters in shortcuts (`<`)' + ) + + assert.equal( + micromark(':a{.ađź’šb}', options()), + '', + 'should support most characters in shortcuts' + ) + + assert.equal( + micromark(':a{_}', options()), + '', + 'should support an underscore in attribute names' + ) + + assert.equal( + micromark(':a{xml:lang}', options()), + '', + 'should support a colon in attribute names' + ) + + assert.equal( + micromark(':a{a="b" c="d e f"}', options()), + '', + 'should support double quoted attributes' + ) + + assert.equal( + micromark(":a{a='b' c='d e f'}", options()), + '', + 'should support single quoted attributes' + ) + + assert.equal( + micromark(':a{a = b c\t=\t\'d\' f =\r"g"}', options()), + '', + 'should support whitespace around initializers' + ) + + assert.equal( + micromark(':a{b==}', options()), + '{b==}
', + 'should not support `=` to start an unquoted attribute value' + ) + + assert.equal( + micromark(':a{b=}', options()), + '{b=}
', + 'should not support a missing attribute value after `=`' + ) + + assert.equal( + micromark(":a{b=c'}", options()), + "{b=c'}
", + 'should not support an apostrophe in an unquoted attribute value' + ) + + assert.equal( + micromark(':a{b=c`}', options()), + '{b=c`}
', + 'should not support a grave accent in an unquoted attribute value' + ) + + assert.equal( + micromark(':a{b=ađź’šb}', options()), + '', + 'should support most other characters in unquoted attribute values' + ) + + assert.equal( + micromark(':a{b="c', options()), + '{b="c
', + 'should not support an EOF in a quoted attribute value' + ) + + assert.equal( + micromark(':a{b="ađź’šb"}', options()), + '', + 'should support most other characters in quoted attribute values' + ) + + assert.equal( + micromark(':a{b="\nc\r d"}', options()), + '', + 'should support EOLs in quoted attribute values' + ) + + assert.equal( + micromark(':a{b="c"', options()), + '{b="c"
', + 'should not support an EOF after a quoted attribute value' + ) }) -test('micromark-extension-directive (compile)', (t) => { - t.equal( +test('micromark-extension-directive (syntax, leaf)', () => { + assert.equal(micromark('::b', options()), '', 'should support a directive') + + assert.equal( + micromark(':', options()), + ':
', + 'should not support one colon' + ) + + assert.equal( + micromark('::', options()), + '::
', + 'should not support two colons not followed by an alpha' + ) + + assert.equal( + micromark('::a', options()), + '', + 'should support two colons followed by an alpha' + ) + + assert.equal( + micromark('::9', options()), + '::9
', + 'should not support two colons followed by a digit' + ) + + assert.equal( + micromark('::-', options()), + '::-
', + 'should not support two colons followed by a dash' + ) + + assert.equal( + micromark('::a9', options()), + '', + 'should support a digit in a name' + ) + + assert.equal( + micromark('::a-b', options()), + '', + 'should support a dash in a name' + ) + + assert.equal( + micromark('::a[', options()), + '::a[
', + 'should not support a name followed by an unclosed `[`' + ) + + assert.equal( + micromark('::a{', options()), + '::a{
', + 'should not support a name followed by an unclosed `{`' + ) + + assert.equal( + micromark('::a[b', options()), + '::a[b
', + 'should not support a name followed by an unclosed `[` w/ content' + ) + + assert.equal( + micromark('::a{b', options()), + '::a{b
', + 'should not support a name followed by an unclosed `{` w/ content' + ) + + assert.equal( + micromark('::a[]', options()), + '', + 'should support an empty label' + ) + + assert.equal( + micromark('::a[ \t]', options()), + '', + 'should support a whitespace only label' + ) + + assert.equal( + micromark('::a[\n]', options()), + '::a[\n]
', + 'should not support an eol in an label' + ) + + assert.equal( + micromark('::a[a b c]', options()), + '', + 'should support content in an label' + ) + + assert.equal( + micromark('::a[a *b* c]', options()), + '', + 'should support markdown in an label' + ) + + assert.equal( + micromark('::a[]asd', options()), + '::a[]asd
', + 'should not support content after a label' + ) + + assert.equal( + micromark('::a{}', options()), + '', + 'should support empty attributes' + ) + + assert.equal( + micromark('::a{ \t}', options()), + '', + 'should support whitespace only attributes' + ) + + assert.equal( + micromark('::a{\n}', options()), + '::a{\n}
', + 'should not support an eol in attributes' + ) + + assert.equal( + micromark('::a{a b c}', options()), + '', + 'should support attributes w/o values' + ) + + assert.equal( + micromark('::a{a=b c=d}', options()), + '', + 'should support attributes w/ unquoted values' + ) + + assert.equal( + micromark('::a{.a .b}', options()), + '', + 'should support attributes w/ class shortcut' + ) + + assert.equal( + micromark('::a{#a #b}', options()), + '', + 'should support attributes w/ id shortcut' + ) + + assert.equal( + micromark('::a{.ađź’šb}', options()), + '', + 'should support most characters in shortcuts' + ) + + assert.equal( + micromark('::a{a="b" c="d e f"}', options()), + '', + 'should support double quoted attributes' + ) + + assert.equal( + micromark("::a{a='b' c='d e f'}", options()), + '', + 'should support single quoted attributes' + ) + + assert.equal( + micromark("::a{a = b c\t=\t'd'}", options()), + '', + 'should support whitespace around initializers' + ) + + assert.equal( + micromark('::a{f =\rg}', options()), + '::a{f =\rg}
', + 'should not support EOLs around initializers' + ) + + assert.equal( + micromark('::a{b==}', options()), + '::a{b==}
', + 'should not support `=` to start an unquoted attribute value' + ) + + assert.equal( + micromark('::a{b=ađź’šb}', options()), + '', + 'should support most other characters in unquoted attribute values' + ) + + assert.equal( + micromark('::a{b="c', options()), + '::a{b="c
', + 'should not support an EOF in a quoted attribute value' + ) + + assert.equal( + micromark('::a{b="ađź’šb"}', options()), + '', + 'should support most other characters in quoted attribute values' + ) + + assert.equal( + micromark('::a{b="\nc\r d"}', options()), + '::a{b="\nc\rd"}
', + 'should not support EOLs in quoted attribute values' + ) + + assert.equal( + micromark('::a{b="c"', options()), + '::a{b="c"
', + 'should not support an EOF after a quoted attribute value' + ) + + assert.equal( + micromark('::a{b=c} \t ', options()), + '', + 'should support whitespace after directives' + ) + + assert.equal( + micromark('::a{b=c}\n>a', options()), + '\n', + 'should support a block quote after a leaf' + ) + + assert.equal( + micromark('::a{b=c}\n```js\na', options()), + 'a
\n
a\n
\n',
+ 'should support code (fenced) after a leaf'
+ )
+
+ assert.equal(
+ micromark('::a{b=c}\n a', options()),
+ 'a\n
',
+ 'should support code (indented) after a leaf'
+ )
+
+ assert.equal(
+ micromark('::a{b=c}\n[a]: b', options()),
+ '',
+ 'should support a definition after a leaf'
+ )
+
+ assert.equal(
+ micromark('::a{b=c}\n# a', options()),
+ 'a
', + 'should support a paragraph after a leaf' + ) + + assert.equal( + micromark('::a{b=c}\n***', options()), + '\n\n', + 'should support a block quote before a leaf' + ) + + assert.equal( + micromark('```js\na\n```\n::a{b=c}', options()), + 'a
\n
a\n
\n',
+ 'should support code (fenced) before a leaf'
+ )
+
+ assert.equal(
+ micromark(' a\n::a{b=c}', options()),
+ 'a\n
\n',
+ 'should support code (indented) before a leaf'
+ )
+
+ assert.equal(
+ micromark('[a]: b\n::a{b=c}', options()),
+ '',
+ 'should support a definition before a leaf'
+ )
+
+ assert.equal(
+ micromark('# a\n::a{b=c}', options()),
+ 'a
\n', + 'should support a paragraph before a leaf' + ) + + assert.equal( + micromark('***\n::a{b=c}', options()), + '\n\n
b
', + 'should not support lazyness (1)' + ) + + assert.equal( + micromark('> a\n::b', options({'*': h})), + '\n\n', + 'should not support lazyness (2)' + ) +}) + +test('micromark-extension-directive (syntax, container)', () => { + assert.equal(micromark(':::b', options()), '', 'should support a directive') + + assert.equal( + micromark(':', options()), + 'a
\n
:
', + 'should not support one colon' + ) + + assert.equal( + micromark('::', options()), + '::
', + 'should not support two colons not followed by an alpha' + ) + + assert.equal( + micromark(':::', options()), + ':::
', + 'should not support three colons not followed by an alpha' + ) + + assert.equal( + micromark(':::a', options()), + '', + 'should support three colons followed by an alpha' + ) + + assert.equal( + micromark(':::9', options()), + ':::9
', + 'should not support three colons followed by a digit' + ) + + assert.equal( + micromark(':::-', options()), + ':::-
', + 'should not support three colons followed by a dash' + ) + + assert.equal( + micromark(':::a9', options()), + '', + 'should support a digit in a name' + ) + + assert.equal( + micromark(':::a-b', options()), + '', + 'should support a dash in a name' + ) + + assert.equal( + micromark(':::a[', options()), + ':::a[
', + 'should not support a name followed by an unclosed `[`' + ) + + assert.equal( + micromark(':::a{', options()), + ':::a{
', + 'should not support a name followed by an unclosed `{`' + ) + + assert.equal( + micromark(':::a[b', options()), + ':::a[b
', + 'should not support a name followed by an unclosed `[` w/ content' + ) + + assert.equal( + micromark(':::a{b', options()), + ':::a{b
', + 'should not support a name followed by an unclosed `{` w/ content' + ) + + assert.equal( + micromark(':::a[]', options()), + '', + 'should support an empty label' + ) + + assert.equal( + micromark(':::a[ \t]', options()), + '', + 'should support a whitespace only label' + ) + + assert.equal( + micromark(':::a[\n]', options()), + ':::a[\n]
', + 'should not support an eol in an label' + ) + + assert.equal( + micromark(':::a[a b c]', options()), + '', + 'should support content in an label' + ) + + assert.equal( + micromark(':::a[a *b* c]', options()), + '', + 'should support markdown in an label' + ) + + assert.equal( + micromark(':::a[]asd', options()), + ':::a[]asd
', + 'should not support content after a label' + ) + + assert.equal( + micromark(':::a{}', options()), + '', + 'should support empty attributes' + ) + + assert.equal( + micromark(':::a{ \t}', options()), + '', + 'should support whitespace only attributes' + ) + + assert.equal( + micromark(':::a{\n}', options()), + ':::a{\n}
', + 'should not support an eol in attributes' + ) + + assert.equal( + micromark(':::a{a b c}', options()), + '', + 'should support attributes' + ) + + assert.equal( + micromark(':::a{f =\rg}', options()), + ':::a{f =\rg}
', + 'should not support EOLs around initializers' + ) + + assert.equal( + micromark(':::a{b="c', options()), + ':::a{b="c
', + 'should not support an EOF in a quoted attribute value' + ) + + assert.equal( + micromark(':::a{b="\nc\r d"}', options()), + ':::a{b="\nc\rd"}
', + 'should not support EOLs in quoted attribute values' + ) + + assert.equal( + micromark(':::a{b="c"', options()), + ':::a{b="c"
', + 'should not support an EOF after a quoted attribute value' + ) + + assert.equal( + micromark(':::a{b=c} \t ', options()), + '', + 'should support whitespace after directives' + ) + + assert.equal( + micromark(':::a\n', options()), + '', + 'should support no closing fence' + ) + + assert.equal( + micromark(':::a\n:::', options()), + '', + 'should support an immediate closing fence' + ) + + assert.equal( + micromark(':::a\n:::\nb', options()), + 'b
', + 'should support content after a closing fence' + ) + + assert.equal( + micromark(':::a\n::\nb', options()), + '', + 'should not close w/ a “closing” fence of two colons' + ) + + assert.equal( + micromark(':::a\n::::\nb', options()), + 'b
', + 'should close w/ a closing fence of more colons' + ) + + assert.equal( + micromark('::::a\n::::\nb', options()), + 'b
', + 'should support more opening colons' + ) + + assert.equal( + micromark(':::::a\n::::\nb', options()), + '', + 'should not close w/ a “closing” fence of less colons than the opening' + ) + + assert.equal( + micromark(':::a\n::: \t\nc', options()), + 'c
', + 'should close w/ a closing fence followed by white space' + ) + + assert.equal( + micromark(':::a\n::: b\nc', options()), + '', + 'should not close w/ a “closing” fence followed by other characters' + ) + + assert.equal( + micromark(':::a\n :::\nc', options()), + 'c
', + 'should close w/ an indented closing fence' + ) + + assert.equal( + micromark(':::a\n\t:::\nc', options()), + '', + 'should not close w/ when the “closing” fence is indented at a tab size' + ) + + assert.equal( + micromark(':::a\n :::\nc', options()), + '', + 'should not close w/ when the “closing” fence is indented more than a tab size' + ) + + assert.equal( + micromark(':::a\n\n \n\ta', options()), + '', + 'should support blank lines in content' + ) + + assert.equal( + micromark(':::a\n\ta\n', options()), + '', + 'should support an EOL EOF' + ) + + assert.equal( + micromark(' :::a\n b\n :::\nc', options()), + 'c
', + 'should support an indented directive' + ) + + assert.equal( + micromark(' :::a\n\t:::\nc', options()), + '', + 'should still not close an indented directive when the “closing” fence is indented a tab size' + ) + + assert.equal( + micromark(':::a\n:::\n>a', options()), + '\n', + 'should support a block quote after a container' + ) + + assert.equal( + micromark(':::a\n:::\n```js\na', options()), + 'a
\n
a\n
\n',
+ 'should support code (fenced) after a container'
+ )
+
+ assert.equal(
+ micromark(':::a\n:::\n a', options()),
+ 'a\n
',
+ 'should support code (indented) after a container'
+ )
+
+ assert.equal(
+ micromark(':::a\n:::\n[a]: b', options()),
+ '',
+ 'should support a definition after a container'
+ )
+
+ assert.equal(
+ micromark(':::a\n:::\n# a', options()),
+ 'a
', + 'should support a paragraph after a container' + ) + + assert.equal( + micromark(':::a\n:::\n***', options()), + '\n\n', + 'should support a block quote before a container' + ) + + assert.equal( + micromark('```js\na\n```\n:::a\nb', options()), + 'a
\n
a\n
\n',
+ 'should support code (fenced) before a container'
+ )
+
+ assert.equal(
+ micromark(' a\n:::a\nb', options()),
+ 'a\n
\n',
+ 'should support code (indented) before a container'
+ )
+
+ assert.equal(
+ micromark('[a]: b\n:::a\nb', options()),
+ '',
+ 'should support a definition before a container'
+ )
+
+ assert.equal(
+ micromark('# a\n:::a\nb', options()),
+ 'a
\n', + 'should support a paragraph before a container' + ) + + assert.equal( + micromark('***\n:::a\nb', options()), + '\n\nb
\n
\n\nb
\n
\n\n
b
', + 'should not support lazyness (1)' + ) + + assert.equal( + micromark('> :::a\n> b\nc', options({'*': h})), + '\n\nb
\n\n
c
', + 'should not support lazyness (2)' + ) + + assert.equal( + micromark('> a\n:::b', options({'*': h})), + '\n\n', + 'should not support lazyness (3)' + ) + + assert.equal( + micromark('> :::a\n:::', options({'*': h})), + 'a
\n
\n\n
:::
', + 'should not support lazyness (4)' + ) +}) + +test('micromark-extension-directive (compile)', () => { + assert.equal( micromark( [ ':abbr', @@ -1177,7 +1176,7 @@ test('micromark-extension-directive (compile)', (t) => { 'should support a directives (abbr)' ) - t.equal( + assert.equal( micromark( [ 'Text:', @@ -1218,41 +1217,39 @@ test('micromark-extension-directive (compile)', (t) => { 'should support directives (youtube)' ) - t.equal( + assert.equal( micromark(':youtube[Cat in a box]\n:br', options({youtube, '*': h})), 'x&y&z
', 'should support character escapes and character references in label' ) - t.equal( + assert.equal( micromark(':abbr[x\\[y\\]z]', options({abbr})), 'x[y]z
', 'should support escaped brackets in a label' ) - t.equal( + assert.equal( micromark(':abbr[x[y]z]', options({abbr})), 'x[y]z
', 'should support balanced brackets in a label' ) - t.equal( + assert.equal( micromark( ':abbr[1[2[3[4[5[6[7[8[9[10[11[12[13[14[15[16[17[18[19[20[21[22[23[24[25[26[27[28[29[30[31[32[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]', options({abbr}) @@ -1261,7 +1258,7 @@ test('content', (t) => { 'should support balanced brackets in a label, 32 levels deep' ) - t.equal( + assert.equal( micromark( ':abbr[1[2[3[4[5[6[7[8[9[10[11[12[13[14[15[16[17[18[19[20[21[22[23[24[25[26[27[28[29[30[31[32[33[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]', options({abbr}) @@ -1270,211 +1267,209 @@ test('content', (t) => { 'should *not* support balanced brackets in a label, 33 levels deep' ) - t.equal( + assert.equal( micromark(':abbr[a\nb\rc]', options({abbr})), 'a\nb\rc
', 'should support EOLs in a label' ) - t.equal( + assert.equal( micromark(':abbr[\na\r]', options({abbr})), '\na\r
', 'should support EOLs at the edges of a label (1)' ) - t.equal( + assert.equal( micromark(':abbr[\n]', options({abbr})), '\n
', 'should support EOLs at the edges of a label (2)' ) - t.equal( + assert.equal( micromark(':abbr[a\n:abbr[b]\nc]', options({abbr})), 'a\nb\nc
', 'should support EOLs around nested directives' ) - t.equal( + assert.equal( micromark(':abbr[:abbr[\n]]', options({abbr})), '\n
', 'should support EOLs inside nested directives (1)' ) - t.equal( + assert.equal( micromark(':abbr[:abbr[a\nb]]', options({abbr})), 'a\nb
', 'should support EOLs inside nested directives (2)' ) - t.equal( + assert.equal( micromark(':abbr[:abbr[\nb\n]]', options({abbr})), '\nb\n
', 'should support EOLs inside nested directives (3)' ) - t.equal( + assert.equal( micromark(':abbr[:abbr[\\\n]]', options({abbr})), '
\n
a b c d
', 'should support markdown in a label' ) - t.equal( + assert.equal( micromark(':abbr{title=a'b}', options({abbr})), '', 'should support character references in unquoted attribute values' ) - t.equal( + assert.equal( micromark(':abbr{title="a'b"}', options({abbr})), '', 'should support character references in double attribute values' ) - t.equal( + assert.equal( micromark(":abbr{title='a'b'}", options({abbr})), '', 'should support character references in single attribute values' ) - t.equal( + assert.equal( micromark(':abbr{title="a&somethingelse;b"}', options({abbr})), '', 'should support unknown character references in attribute values' ) - t.equal( + assert.equal( micromark(':a{href=¶m}', options({'*': h})), '', 'should not support non-terminated character references in unquoted attribute values' ) - t.equal( + assert.equal( micromark(':a{href="¶m"}', options({'*': h})), '', 'should not support non-terminated character references in double quoted attribute values' ) - t.equal( + assert.equal( micromark(":a{href='¶m'}", options({'*': h})), '', 'should not support non-terminated character references in single quoted attribute values' ) - t.equal( + assert.equal( micromark(':span{a\nb}', options({'*': h})), '', 'should support EOLs between attributes' ) - t.equal( + assert.equal( micromark(':span{\na\n}', options({'*': h})), '
', 'should support EOLs at the edges of attributes' ) - t.equal( + assert.equal( micromark(':span{a\r= b}', options({'*': h})), '
', 'should support EOLs before initializer' ) - t.equal( + assert.equal( micromark(':span{a=\r\nb}', options({'*': h})), '
', 'should support EOLs after initializer' ) - t.equal( + assert.equal( micromark(':span{a=b\nc}', options({'*': h})), '
', 'should support EOLs between an unquoted attribute value and a next attribute name' ) - t.equal( + assert.equal( micromark(':span{a="b\nc"}', options({'*': h})), '
', 'should support EOLs in a double quoted attribute value' ) - t.equal( + assert.equal( micromark(":span{a='b\nc'}", options({'*': h})), '
', 'should support EOLs in a single quoted attribute value' ) - t.equal( + assert.equal( micromark(':span{#a#b}', options({'*': h})), '
', 'should support `id` shortcuts' ) - t.equal( + assert.equal( micromark(':span{id=a id="b" #c#d}', options({'*': h})), '
', 'should support `id` shortcuts after `id` attributes' ) - t.equal( + assert.equal( micromark(':span{.a.b}', options({'*': h})), '
', 'should support `class` shortcuts' ) - t.equal( + assert.equal( micromark(':span{class=a class="b c" .d.e}', options({'*': h})), '
', 'should support `class` shortcuts after `class` attributes' ) - t.equal( + assert.equal( micromark('::::div{.big}\n:::div{.small}\nText', options({'*': h})), '
Text
\nText
\n