From b13db32db44846fdcbcaa77eb9146d3453690048 Mon Sep 17 00:00:00 2001 From: HidemaruOwO Date: Thu, 6 Feb 2025 22:19:50 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix=20(test/index.js)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/index.js | 1772 ------------------------------------------------- 1 file changed, 1772 deletions(-) delete mode 100644 test/index.js diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 9886878..0000000 --- a/test/index.js +++ /dev/null @@ -1,1772 +0,0 @@ -/** - * @import {Handle, HtmlOptions} from 'micromark-extension-directive' - * @import {CompileContext} from 'micromark-util-types' - */ - -import assert from 'node:assert/strict' -import test from 'node:test' -import {micromark} from 'micromark' -import {htmlVoidElements} from 'html-void-elements' -import {directive, directiveHtml} from 'micromark-extension-directive' - -const own = {}.hasOwnProperty - -test('micromark-extension-directive (core)', async function (t) { - await t.test('should expose the public api', async function () { - assert.deepEqual( - Object.keys(await import('micromark-extension-directive')).sort(), - ['directive', 'directiveHtml'] - ) - }) -}) - -test('micromark-extension-directive (syntax, text)', async function (t) { - await t.test( - 'should support an escaped colon which would otherwise be a directive', - async function () { - assert.equal(micromark('\\:a', options()), '

:a

') - } - ) - - await t.test( - 'should support a directive after an escaped colon', - async function () { - assert.equal(micromark('\\::a', options()), '

:

') - } - ) - - await t.test( - 'should not support a directive after a colon', - async function () { - assert.equal(micromark('a ::b', options()), '

a ::b

') - } - ) - - await t.test( - 'should not support a colon not followed by an alpha', - async function () { - assert.equal(micromark(':', options()), '

:

') - } - ) - - await t.test( - 'should support a colon followed by an alpha', - async function () { - assert.equal(micromark(':a', options()), '

') - } - ) - - await t.test( - 'should not support a colon followed by a digit', - async function () { - assert.equal(micromark(':9', options()), '

:9

') - } - ) - - await t.test( - 'should not support a colon followed by a dash', - async function () { - assert.equal(micromark(':-', options()), '

:-

') - } - ) - - await t.test( - 'should not support a colon followed by an underscore', - async function () { - assert.equal(micromark(':_', options()), '

:_

') - } - ) - - await t.test('should support a digit in a name', async function () { - assert.equal(micromark(':a9', options()), '

') - }) - - await t.test('should support a dash in a name', async function () { - assert.equal(micromark(':a-b', options()), '

') - }) - - await t.test( - 'should *not* support a dash at the end of a name', - async function () { - assert.equal(micromark(':a-', options()), '

:a-

') - } - ) - - await t.test('should support an underscore in a name', async function () { - assert.equal(micromark(':a_b', options()), '

') - }) - - await t.test( - 'should *not* support an underscore at the end of a name', - async function () { - assert.equal(micromark(':a_', options()), '

:a_

') - } - ) - - await t.test( - 'should *not* support a colon right after a name', - async function () { - assert.equal(micromark(':a:', options()), '

:a:

') - } - ) - - await t.test('should not interfere w/ gemoji (1)', async function () { - assert.equal(micromark(':+1:', options()), '

:+1:

') - }) - - await t.test('should not interfere w/ gemoji (2)', async function () { - assert.equal(micromark(':heart:', options()), '

:heart:

') - }) - - await t.test('should not interfere w/ gemoji (3)', async function () { - assert.equal( - micromark(':call_me_hand:', options()), - '

:call_me_hand:

' - ) - }) - - await t.test('should not interfere w/ emphasis (`_`)', async function () { - assert.equal( - micromark('_:directive_', options()), - '

:directive

' - ) - }) - - await t.test( - 'should support a name followed by an unclosed `[`', - async function () { - assert.equal(micromark(':a[', options()), '

[

') - } - ) - - await t.test( - 'should support a name followed by an unclosed `{`', - async function () { - assert.equal(micromark(':a{', options()), '

{

') - } - ) - - await t.test( - 'should support a name followed by an unclosed `[` w/ content', - async function () { - assert.equal(micromark(':a[b', options()), '

[b

') - } - ) - - await t.test( - 'should support a name followed by an unclosed `{` w/ content', - async function () { - assert.equal(micromark(':a{b', options()), '

{b

') - } - ) - - await t.test('should support an empty label', async function () { - assert.equal(micromark(':a[]', options()), '

') - }) - - await t.test('should support a whitespace only label', async function () { - assert.equal(micromark(':a[ \t]', options()), '

') - }) - - await t.test('should support an eol in an label', async function () { - assert.equal(micromark(':a[\n]', options()), '

') - }) - - await t.test('should support content in an label', async function () { - assert.equal(micromark(':a[a b c]asd', options()), '

asd

') - }) - - await t.test('should support markdown in an label', async function () { - assert.equal(micromark(':a[a *b* c]asd', options()), '

asd

') - }) - - await t.test( - 'should support markdown in an label (hard break)', - async function () { - assert.equal( - micromark(':x[a \nb]c', options({'*': h})), - '

a
\nb
c

' - ) - } - ) - - await t.test('should support a directive in an label', async function () { - assert.equal(micromark('a :b[c :d[e] f] g', options()), '

a g

') - }) - - await t.test('should support content after a label', async function () { - assert.equal(micromark(':a[]asd', options()), '

asd

') - }) - - await t.test('should support empty attributes', async function () { - assert.equal(micromark(':a{}', options()), '

') - }) - - await t.test('should support whitespace only attributes', async function () { - assert.equal(micromark(':a{ \t}', options()), '

') - }) - - await t.test('should support an eol in attributes', async function () { - assert.equal(micromark(':a{\n}', options()), '

') - }) - - await t.test('should support attributes w/o values', async function () { - assert.equal(micromark(':a{a b c}', options()), '

') - }) - - await t.test( - 'should support attributes w/ unquoted values', - async function () { - assert.equal(micromark(':a{a=b c=d}', options()), '

') - } - ) - - await t.test( - 'should support attributes w/ class shortcut', - async function () { - assert.equal(micromark(':a{.a .b}', options()), '

') - } - ) - - await t.test( - 'should support attributes w/ class shortcut w/o whitespace between', - async function () { - assert.equal(micromark(':a{.a.b}', options()), '

') - } - ) - - await t.test('should support attributes w/ id shortcut', async function () { - assert.equal(micromark(':a{#a #b}', options()), '

') - }) - - await t.test( - 'should support attributes w/ id shortcut w/o whitespace between', - async function () { - assert.equal(micromark(':a{#a#b}', options()), '

') - } - ) - - await t.test( - 'should support attributes w/ shortcuts combined w/ other attributes', - async function () { - assert.equal(micromark(':a{#a.b.c#d e f=g #h.i.j}', options()), '

') - } - ) - - await t.test('should not support an empty shortcut (`.`)', async function () { - assert.equal(micromark(':a{..b}', options()), '

{..b}

') - }) - - await t.test('should not support an empty shortcut (`#`)', async function () { - assert.equal(micromark(':a{.#b}', options()), '

{.#b}

') - }) - - await t.test('should not support an empty shortcut (`}`)', async function () { - assert.equal(micromark(':a{.}', options()), '

{.}

') - }) - - await t.test( - 'should not support certain characters in shortcuts (`=`)', - async function () { - assert.equal(micromark(':a{.a=b}', options()), '

{.a=b}

') - } - ) - - await t.test( - 'should not support certain characters in shortcuts (`"`)', - async function () { - assert.equal(micromark(':a{.a"b}', options()), '

{.a"b}

') - } - ) - - await t.test( - 'should not support certain characters in shortcuts (`<`)', - async function () { - assert.equal(micromark(':a{.a{.a<b}

') - } - ) - - await t.test( - 'should support most characters in shortcuts', - async function () { - assert.equal(micromark(':a{.ađź’šb}', options()), '

') - } - ) - - await t.test( - 'should support an underscore in attribute names', - async function () { - assert.equal(micromark(':a{_}', options()), '

') - } - ) - - await t.test('should support a colon in attribute names', async function () { - assert.equal(micromark(':a{xml:lang}', options()), '

') - }) - - await t.test('should support double quoted attributes', async function () { - assert.equal(micromark(':a{a="b" c="d e f"}', options()), '

') - }) - - await t.test('should support single quoted attributes', async function () { - assert.equal(micromark(":a{a='b' c='d e f'}", options()), '

') - }) - - await t.test( - 'should support whitespace around initializers', - async function () { - assert.equal( - micromark(':a{a = b c\t=\t\'d\' f =\r"g"}', options()), - '

' - ) - } - ) - - await t.test( - 'should not support `=` to start an unquoted attribute value', - async function () { - assert.equal(micromark(':a{b==}', options()), '

{b==}

') - } - ) - - await t.test( - 'should not support a missing attribute value after `=`', - async function () { - assert.equal(micromark(':a{b=}', options()), '

{b=}

') - } - ) - - await t.test( - 'should not support an apostrophe in an unquoted attribute value', - async function () { - assert.equal(micromark(":a{b=c'}", options()), "

{b=c'}

") - } - ) - - await t.test( - 'should not support a grave accent in an unquoted attribute value', - async function () { - assert.equal(micromark(':a{b=c`}', options()), '

{b=c`}

') - } - ) - - await t.test( - 'should support most other characters in unquoted attribute values', - async function () { - assert.equal(micromark(':a{b=ađź’šb}', options()), '

') - } - ) - - await t.test( - 'should not support an EOF in a quoted attribute value', - async function () { - assert.equal(micromark(':a{b="c', options()), '

{b="c

') - } - ) - - await t.test( - 'should support most other characters in quoted attribute values', - async function () { - assert.equal(micromark(':a{b="ađź’šb"}', options()), '

') - } - ) - - await t.test( - 'should support EOLs in quoted attribute values', - async function () { - assert.equal(micromark(':a{b="\nc\r d"}', options()), '

') - } - ) - - await t.test( - 'should not support an EOF after a quoted attribute value', - async function () { - assert.equal(micromark(':a{b="c"', options()), '

{b="c"

') - } - ) -}) - -test('micromark-extension-directive (syntax, leaf)', async function (t) { - await t.test('should support a directive', async function () { - assert.equal(micromark('::b', options()), '') - }) - - await t.test('should not support one colon', async function () { - assert.equal(micromark(':', options()), '

:

') - }) - - await t.test( - 'should not support two colons not followed by an alpha', - async function () { - assert.equal(micromark('::', options()), '

::

') - } - ) - - await t.test( - 'should support two colons followed by an alpha', - async function () { - assert.equal(micromark('::a', options()), '') - } - ) - - await t.test( - 'should not support two colons followed by a digit', - async function () { - assert.equal(micromark('::9', options()), '

::9

') - } - ) - - await t.test( - 'should not support two colons followed by a dash', - async function () { - assert.equal(micromark('::-', options()), '

::-

') - } - ) - - await t.test('should support a digit in a name', async function () { - assert.equal(micromark('::a9', options()), '') - }) - - await t.test('should support a dash in a name', async function () { - assert.equal(micromark('::a-b', options()), '') - }) - - await t.test( - 'should not support a name followed by an unclosed `[`', - async function () { - assert.equal(micromark('::a[', options()), '

::a[

') - } - ) - - await t.test( - 'should not support a name followed by an unclosed `{`', - async function () { - assert.equal(micromark('::a{', options()), '

::a{

') - } - ) - - await t.test( - 'should not support a name followed by an unclosed `[` w/ content', - async function () { - assert.equal(micromark('::a[b', options()), '

::a[b

') - } - ) - - await t.test( - 'should not support a name followed by an unclosed `{` w/ content', - async function () { - assert.equal(micromark('::a{b', options()), '

::a{b

') - } - ) - - await t.test('should support an empty label', async function () { - assert.equal(micromark('::a[]', options()), '') - }) - - await t.test('should support a whitespace only label', async function () { - assert.equal(micromark('::a[ \t]', options()), '') - }) - - await t.test('should not support an eol in an label', async function () { - assert.equal(micromark('::a[\n]', options()), '

::a[\n]

') - }) - - await t.test('should support content in an label', async function () { - assert.equal(micromark('::a[a b c]', options()), '') - }) - - await t.test('should support markdown in an label', async function () { - assert.equal(micromark('::a[a *b* c]', options()), '') - }) - - await t.test('should not support content after a label', async function () { - assert.equal(micromark('::a[]asd', options()), '

::a[]asd

') - }) - - await t.test('should support empty attributes', async function () { - assert.equal(micromark('::a{}', options()), '') - }) - - await t.test('should support whitespace only attributes', async function () { - assert.equal(micromark('::a{ \t}', options()), '') - }) - - await t.test('should not support an eol in attributes', async function () { - assert.equal(micromark('::a{\n}', options()), '

::a{\n}

') - }) - - await t.test('should support attributes w/o values', async function () { - assert.equal(micromark('::a{a b c}', options()), '') - }) - - await t.test( - 'should support attributes w/ unquoted values', - async function () { - assert.equal(micromark('::a{a=b c=d}', options()), '') - } - ) - - await t.test( - 'should support attributes w/ class shortcut', - async function () { - assert.equal(micromark('::a{.a .b}', options()), '') - } - ) - - await t.test('should support attributes w/ id shortcut', async function () { - assert.equal(micromark('::a{#a #b}', options()), '') - }) - - await t.test( - 'should support most characters in shortcuts', - async function () { - assert.equal(micromark('::a{.ađź’šb}', options()), '') - } - ) - - await t.test('should support double quoted attributes', async function () { - assert.equal(micromark('::a{a="b" c="d e f"}', options()), '') - }) - - await t.test('should support single quoted attributes', async function () { - assert.equal(micromark("::a{a='b' c='d e f'}", options()), '') - }) - - await t.test( - 'should support whitespace around initializers', - async function () { - assert.equal(micromark("::a{a = b c\t=\t'd'}", options()), '') - } - ) - - await t.test( - 'should not support EOLs around initializers', - async function () { - assert.equal(micromark('::a{f =\rg}', options()), '

::a{f =\rg}

') - } - ) - - await t.test( - 'should not support `=` to start an unquoted attribute value', - async function () { - assert.equal(micromark('::a{b==}', options()), '

::a{b==}

') - } - ) - - await t.test( - 'should support most other characters in unquoted attribute values', - async function () { - assert.equal(micromark('::a{b=ađź’šb}', options()), '') - } - ) - - await t.test( - 'should not support an EOF in a quoted attribute value', - async function () { - assert.equal(micromark('::a{b="c', options()), '

::a{b="c

') - } - ) - - await t.test( - 'should support most other characters in quoted attribute values', - async function () { - assert.equal(micromark('::a{b="ađź’šb"}', options()), '') - } - ) - - await t.test( - 'should not support EOLs in quoted attribute values', - async function () { - assert.equal( - micromark('::a{b="\nc\r d"}', options()), - '

::a{b="\nc\rd"}

' - ) - } - ) - - await t.test( - 'should not support an EOF after a quoted attribute value', - async function () { - assert.equal( - micromark('::a{b="c"', options()), - '

::a{b="c"

' - ) - } - ) - - await t.test('should support whitespace after directives', async function () { - assert.equal(micromark('::a{b=c} \t ', options()), '') - }) - - await t.test('should support a block quote after a leaf', async function () { - assert.equal( - micromark('::a{b=c}\n>a', options()), - '
\n

a

\n
' - ) - }) - - await t.test('should support code (fenced) after a leaf', async function () { - assert.equal( - micromark('::a{b=c}\n```js\na', options()), - '
a\n
\n' - ) - }) - - await t.test( - 'should support code (indented) after a leaf', - async function () { - assert.equal( - micromark('::a{b=c}\n a', options()), - '
a\n
' - ) - } - ) - - await t.test('should support a definition after a leaf', async function () { - assert.equal(micromark('::a{b=c}\n[a]: b', options()), '') - }) - - await t.test( - 'should support a heading (atx) after a leaf', - async function () { - assert.equal(micromark('::a{b=c}\n# a', options()), '

a

') - } - ) - - await t.test( - 'should support a heading (setext) after a leaf', - async function () { - assert.equal(micromark('::a{b=c}\na\n=', options()), '

a

') - } - ) - - await t.test('should support html after a leaf', async function () { - assert.equal(micromark('::a{b=c}\n', options()), '') - }) - - await t.test('should support a list after a leaf', async function () { - assert.equal( - micromark('::a{b=c}\n* a', options()), - '' - ) - }) - - await t.test('should support a paragraph after a leaf', async function () { - assert.equal(micromark('::a{b=c}\na', options()), '

a

') - }) - - await t.test( - 'should support a thematic break after a leaf', - async function () { - assert.equal(micromark('::a{b=c}\n***', options()), '
') - } - ) - - await t.test('should support a block quote before a leaf', async function () { - assert.equal( - micromark('>a\n::a{b=c}', options()), - '
\n

a

\n
\n' - ) - }) - - await t.test('should support code (fenced) before a leaf', async function () { - assert.equal( - micromark('```js\na\n```\n::a{b=c}', options()), - '
a\n
\n' - ) - }) - - await t.test( - 'should support code (indented) before a leaf', - async function () { - assert.equal( - micromark(' a\n::a{b=c}', options()), - '
a\n
\n' - ) - } - ) - - await t.test('should support a definition before a leaf', async function () { - assert.equal(micromark('[a]: b\n::a{b=c}', options()), '') - }) - - await t.test( - 'should support a heading (atx) before a leaf', - async function () { - assert.equal(micromark('# a\n::a{b=c}', options()), '

a

\n') - } - ) - - await t.test( - 'should support a heading (setext) before a leaf', - async function () { - assert.equal(micromark('a\n=\n::a{b=c}', options()), '

a

\n') - } - ) - - await t.test('should support html before a leaf', async function () { - assert.equal(micromark('\n::a{b=c}', options()), '\n') - }) - - await t.test('should support a list before a leaf', async function () { - assert.equal( - micromark('* a\n::a{b=c}', options()), - '\n' - ) - }) - - await t.test('should support a paragraph before a leaf', async function () { - assert.equal(micromark('a\n::a{b=c}', options()), '

a

\n') - }) - - await t.test( - 'should support a thematic break before a leaf', - async function () { - assert.equal(micromark('***\n::a{b=c}', options()), '
\n') - } - ) - - await t.test('should not support lazyness (1)', async function () { - assert.equal( - micromark('> ::a\nb', options({'*': h})), - '
\n
\n

b

' - ) - }) - - await t.test('should not support lazyness (2)', async function () { - assert.equal( - micromark('> a\n::b', options({'*': h})), - '
\n

a

\n
\n' - ) - }) -}) - -test('micromark-extension-directive (syntax, container)', async function (t) { - await t.test('should support a directive', async function () { - assert.equal(micromark(':::b', options()), '') - }) - - await t.test('should not support one colon', async function () { - assert.equal(micromark(':', options()), '

:

') - }) - - await t.test( - 'should not support two colons not followed by an alpha', - async function () { - assert.equal(micromark('::', options()), '

::

') - } - ) - - await t.test( - 'should not support three colons not followed by an alpha', - async function () { - assert.equal(micromark(':::', options()), '

:::

') - } - ) - - await t.test( - 'should support three colons followed by an alpha', - async function () { - assert.equal(micromark(':::a', options()), '') - } - ) - - await t.test( - 'should not support three colons followed by a digit', - async function () { - assert.equal(micromark(':::9', options()), '

:::9

') - } - ) - - await t.test( - 'should not support three colons followed by a dash', - async function () { - assert.equal(micromark(':::-', options()), '

:::-

') - } - ) - - await t.test('should support a digit in a name', async function () { - assert.equal(micromark(':::a9', options()), '') - }) - - await t.test('should support a dash in a name', async function () { - assert.equal(micromark(':::a-b', options()), '') - }) - - await t.test( - 'should not support a name followed by an unclosed `[`', - async function () { - assert.equal(micromark(':::a[', options()), '

:::a[

') - } - ) - - await t.test( - 'should not support a name followed by an unclosed `{`', - async function () { - assert.equal(micromark(':::a{', options()), '

:::a{

') - } - ) - - await t.test( - 'should not support a name followed by an unclosed `[` w/ content', - async function () { - assert.equal(micromark(':::a[b', options()), '

:::a[b

') - } - ) - - await t.test( - 'should not support a name followed by an unclosed `{` w/ content', - async function () { - assert.equal(micromark(':::a{b', options()), '

:::a{b

') - } - ) - - await t.test('should support an empty label', async function () { - assert.equal(micromark(':::a[]', options()), '') - }) - - await t.test('should support a whitespace only label', async function () { - assert.equal(micromark(':::a[ \t]', options()), '') - }) - - await t.test('should not support an eol in an label', async function () { - assert.equal(micromark(':::a[\n]', options()), '

:::a[\n]

') - }) - - await t.test('should support content in an label', async function () { - assert.equal(micromark(':::a[a b c]', options()), '') - }) - - await t.test('should support markdown in an label', async function () { - assert.equal(micromark(':::a[a *b* c]', options()), '') - }) - - await t.test('should not support content after a label', async function () { - assert.equal(micromark(':::a[]asd', options()), '

:::a[]asd

') - }) - - await t.test('should support empty attributes', async function () { - assert.equal(micromark(':::a{}', options()), '') - }) - - await t.test('should support whitespace only attributes', async function () { - assert.equal(micromark(':::a{ \t}', options()), '') - }) - - await t.test('should not support an eol in attributes', async function () { - assert.equal(micromark(':::a{\n}', options()), '

:::a{\n}

') - }) - - await t.test('should support attributes', async function () { - assert.equal(micromark(':::a{a b c}', options()), '') - }) - - await t.test( - 'should not support EOLs around initializers', - async function () { - assert.equal( - micromark(':::a{f =\rg}', options()), - '

:::a{f =\rg}

' - ) - } - ) - - await t.test( - 'should not support an EOF in a quoted attribute value', - async function () { - assert.equal(micromark(':::a{b="c', options()), '

:::a{b="c

') - } - ) - - await t.test( - 'should not support EOLs in quoted attribute values', - async function () { - assert.equal( - micromark(':::a{b="\nc\r d"}', options()), - '

:::a{b="\nc\rd"}

' - ) - } - ) - - await t.test( - 'should not support an EOF after a quoted attribute value', - async function () { - assert.equal( - micromark(':::a{b="c"', options()), - '

:::a{b="c"

' - ) - } - ) - - await t.test('should support whitespace after directives', async function () { - assert.equal(micromark(':::a{b=c} \t ', options()), '') - }) - - await t.test('should support no closing fence', async function () { - assert.equal(micromark(':::a\n', options()), '') - }) - - await t.test('should support an immediate closing fence', async function () { - assert.equal(micromark(':::a\n:::', options()), '') - }) - - await t.test( - 'should support content after a closing fence', - async function () { - assert.equal(micromark(':::a\n:::\nb', options()), '

b

') - } - ) - - await t.test( - 'should not close w/ a “closing” fence of two colons', - async function () { - assert.equal(micromark(':::a\n::\nb', options()), '') - } - ) - - await t.test( - 'should close w/ a closing fence of more colons', - async function () { - assert.equal(micromark(':::a\n::::\nb', options()), '

b

') - } - ) - - await t.test('should support more opening colons', async function () { - assert.equal(micromark('::::a\n::::\nb', options()), '

b

') - }) - - await t.test( - 'should not close w/ a “closing” fence of less colons than the opening', - async function () { - assert.equal(micromark(':::::a\n::::\nb', options()), '') - } - ) - - await t.test( - 'should close w/ a closing fence followed by white space', - async function () { - assert.equal(micromark(':::a\n::: \t\nc', options()), '

c

') - } - ) - - await t.test( - 'should not close w/ a “closing” fence followed by other characters', - async function () { - assert.equal(micromark(':::a\n::: b\nc', options()), '') - } - ) - - await t.test('should close w/ an indented closing fence', async function () { - assert.equal(micromark(':::a\n :::\nc', options()), '

c

') - }) - - await t.test( - 'should not close w/ when the “closing” fence is indented at a tab size', - async function () { - assert.equal(micromark(':::a\n\t:::\nc', options()), '') - } - ) - - await t.test( - 'should not close w/ when the “closing” fence is indented more than a tab size', - async function () { - assert.equal(micromark(':::a\n :::\nc', options()), '') - } - ) - - await t.test('should support blank lines in content', async function () { - assert.equal(micromark(':::a\n\n \n\ta', options()), '') - }) - - await t.test('should support an EOL EOF', async function () { - assert.equal(micromark(':::a\n\ta\n', options()), '') - }) - - await t.test('should support an indented directive', async function () { - assert.equal(micromark(' :::a\n b\n :::\nc', options()), '

c

') - }) - - await t.test( - 'should still not close an indented directive when the “closing” fence is indented a tab size', - async function () { - assert.equal(micromark(' :::a\n\t:::\nc', options()), '') - } - ) - - await t.test( - 'should strip arbitrary length prefix from closing fence line (codeIndented disabled)', - async function () { - assert.equal( - micromark(':::x\nalpha.\n :::\n\nbravo.', { - allowDangerousHtml: true, - extensions: [directive(), {disable: {null: ['codeIndented']}}], - htmlExtensions: [directiveHtml()] - }), - '

bravo.

' - ) - } - ) - - await t.test( - 'should support a block quote after a container', - async function () { - assert.equal( - micromark(':::a\n:::\n>a', options()), - '
\n

a

\n
' - ) - } - ) - - await t.test( - 'should support code (fenced) after a container', - async function () { - assert.equal( - micromark(':::a\n:::\n```js\na', options()), - '
a\n
\n' - ) - } - ) - - await t.test( - 'should support code (indented) after a container', - async function () { - assert.equal( - micromark(':::a\n:::\n a', options()), - '
a\n
' - ) - } - ) - - await t.test( - 'should support a definition after a container', - async function () { - assert.equal(micromark(':::a\n:::\n[a]: b', options()), '') - } - ) - - await t.test( - 'should support a heading (atx) after a container', - async function () { - assert.equal(micromark(':::a\n:::\n# a', options()), '

a

') - } - ) - - await t.test( - 'should support a heading (setext) after a container', - async function () { - assert.equal(micromark(':::a\n:::\na\n=', options()), '

a

') - } - ) - - await t.test('should support html after a container', async function () { - assert.equal(micromark(':::a\n:::\n', options()), '') - }) - - await t.test('should support a list after a container', async function () { - assert.equal( - micromark(':::a\n:::\n* a', options()), - '' - ) - }) - - await t.test( - 'should support a paragraph after a container', - async function () { - assert.equal(micromark(':::a\n:::\na', options()), '

a

') - } - ) - - await t.test( - 'should support a thematic break after a container', - async function () { - assert.equal(micromark(':::a\n:::\n***', options()), '
') - } - ) - - await t.test( - 'should support a block quote before a container', - async function () { - assert.equal( - micromark('>a\n:::a\nb', options()), - '
\n

a

\n
\n' - ) - } - ) - - await t.test( - 'should support code (fenced) before a container', - async function () { - assert.equal( - micromark('```js\na\n```\n:::a\nb', options()), - '
a\n
\n' - ) - } - ) - - await t.test( - 'should support code (indented) before a container', - async function () { - assert.equal( - micromark(' a\n:::a\nb', options()), - '
a\n
\n' - ) - } - ) - - await t.test( - 'should support a definition before a container', - async function () { - assert.equal(micromark('[a]: b\n:::a\nb', options()), '') - } - ) - - await t.test( - 'should support a heading (atx) before a container', - async function () { - assert.equal(micromark('# a\n:::a\nb', options()), '

a

\n') - } - ) - - await t.test( - 'should support a heading (setext) before a container', - async function () { - assert.equal(micromark('a\n=\n:::a\nb', options()), '

a

\n') - } - ) - - await t.test('should support html before a container', async function () { - assert.equal(micromark('\n:::a\nb', options()), '\n') - }) - - await t.test('should support a list before a container', async function () { - assert.equal( - micromark('* a\n:::a\nb', options()), - '\n' - ) - }) - - await t.test( - 'should support a paragraph before a container', - async function () { - assert.equal(micromark('a\n:::a\nb', options()), '

a

\n') - } - ) - - await t.test( - 'should support a thematic break before a container', - async function () { - assert.equal(micromark('***\n:::a\nb', options()), '
\n') - } - ) - - await t.test('should support prefixed containers (1)', async function () { - assert.equal(micromark(' :::x\n ', options({'*': h})), '') - }) - - await t.test('should support prefixed containers (2)', async function () { - assert.equal( - micromark(' :::x\n - a', options({'*': h})), - '\n
    \n
  • a
  • \n
\n
' - ) - }) - - await t.test('should support prefixed containers (3)', async function () { - assert.equal( - micromark(' :::x\n - a\n > b', options({'*': h})), - '\n
    \n
  • a
  • \n
\n
\n

b

\n
\n
' - ) - }) - - await t.test('should support prefixed containers (4)', async function () { - assert.equal( - micromark(' :::x\n - a\n > b\n :::', options({'*': h})), - '\n
    \n
  • a
  • \n
\n
\n

b

\n
\n
' - ) - }) - - await t.test('should not support lazyness (1)', async function () { - assert.equal( - micromark('> :::a\nb', options({'*': h})), - '
\n
\n

b

' - ) - }) - - await t.test('should not support lazyness (2)', async function () { - assert.equal( - micromark('> :::a\n> b\nc', options({'*': h})), - '
\n

b

\n
\n
\n

c

' - ) - }) - - await t.test('should not support lazyness (3)', async function () { - assert.equal( - micromark('> a\n:::b', options({'*': h})), - '
\n

a

\n
\n' - ) - }) - - await t.test('should not support lazyness (4)', async function () { - assert.equal( - micromark('> :::a\n:::', options({'*': h})), - '
\n
\n

:::

' - ) - }) -}) - -test('micromark-extension-directive (compile)', async function (t) { - await t.test('should support a directives (abbr)', async function () { - assert.equal( - micromark( - [ - ':abbr', - ':abbr[HTML]', - ':abbr{title="HyperText Markup Language"}', - ':abbr[HTML]{title="HyperText Markup Language"}' - ].join('\n\n'), - options({abbr}) - ), - [ - '

', - '

HTML

', - '

', - '

HTML

' - ].join('\n') - ) - }) - - await t.test('should support directives (youtube)', async function () { - assert.equal( - micromark( - [ - 'Text:', - ':youtube', - ':youtube[Cat in a box a]', - ':youtube{v=1}', - ':youtube[Cat in a box b]{v=2}', - 'Leaf:', - '::youtube', - '::youtube[Cat in a box c]', - '::youtube{v=3}', - '::youtube[Cat in a box d]{v=4}', - 'Container:', - ':::youtube\nw\n:::', - ':::youtube[Cat in a box e]\nx\n:::', - ':::youtube{v=5}\ny\n:::', - ':::youtube[Cat in a box f]{v=6}\nz\n:::' - ].join('\n\n'), - options({youtube}) - ), - [ - '

Text:

', - '

', - '

', - '

', - '

', - '

Leaf:

', - '', - '', - '

Container:

', - '', - '' - ].join('\n') - ) - }) - - await t.test( - 'should support fall through directives (`*`)', - async function () { - assert.equal( - micromark(':youtube[Cat in a box]\n:br', options({youtube, '*': h})), - '

Cat in a box\n

' - ) - } - ) - - await t.test( - 'should support fall through directives (`*`)', - async function () { - assert.equal( - micromark(':a[:img{src="x" alt=y}]{href="z"}', options({'*': h})), - '

y

' - ) - } - ) -}) - -test('content', async function (t) { - await t.test( - 'should support character escapes and character references in label', - async function () { - assert.equal( - micromark(':abbr[x\\&y&z]', options({abbr})), - '

x&y&z

' - ) - } - ) - - await t.test('should support escaped brackets in a label', async function () { - assert.equal( - micromark(':abbr[x\\[y\\]z]', options({abbr})), - '

x[y]z

' - ) - }) - - await t.test( - 'should support balanced brackets in a label', - async function () { - assert.equal( - micromark(':abbr[x[y]z]', options({abbr})), - '

x[y]z

' - ) - } - ) - - await t.test( - 'should support balanced brackets in a label, 32 levels deep', - async function () { - 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}) - ), - '

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]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

' - ) - } - ) - - await t.test( - 'should *not* support balanced brackets in a label, 33 levels deep', - async function () { - 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}) - ), - '

[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]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

' - ) - } - ) - - await t.test('should support EOLs in a label', async function () { - assert.equal( - micromark(':abbr[a\nb\rc]', options({abbr})), - '

a\nb\rc

' - ) - }) - - await t.test( - 'should support EOLs at the edges of a label (1)', - async function () { - assert.equal( - micromark(':abbr[\na\r]', options({abbr})), - '

\na\r

' - ) - } - ) - - await t.test( - 'should support EOLs at the edges of a label (2)', - async function () { - assert.equal( - micromark(':abbr[\n]', options({abbr})), - '

\n

' - ) - } - ) - - await t.test( - 'should support EOLs around nested directives', - async function () { - assert.equal( - micromark(':abbr[a\n:abbr[b]\nc]', options({abbr})), - '

a\nb\nc

' - ) - } - ) - - await t.test( - 'should support EOLs inside nested directives (1)', - async function () { - assert.equal( - micromark(':abbr[:abbr[\n]]', options({abbr})), - '

\n

' - ) - } - ) - - await t.test( - 'should support EOLs inside nested directives (2)', - async function () { - assert.equal( - micromark(':abbr[:abbr[a\nb]]', options({abbr})), - '

a\nb

' - ) - } - ) - - await t.test( - 'should support EOLs inside nested directives (3)', - async function () { - assert.equal( - micromark(':abbr[:abbr[\nb\n]]', options({abbr})), - '

\nb\n

' - ) - } - ) - - await t.test( - 'should support EOLs inside nested directives (4)', - async function () { - assert.equal( - micromark(':abbr[:abbr[\\\n]]', options({abbr})), - '


\n

' - ) - } - ) - - await t.test('should support markdown in a label', async function () { - assert.equal( - micromark(':abbr[a *b* **c** d]', options({abbr})), - '

a b c d

' - ) - }) - - await t.test( - 'should support character references in unquoted attribute values', - async function () { - assert.equal( - micromark(':abbr{title=a'b}', options({abbr})), - '

' - ) - } - ) - - await t.test( - 'should support character references in double attribute values', - async function () { - assert.equal( - micromark(':abbr{title="a'b"}', options({abbr})), - '

' - ) - } - ) - - await t.test( - 'should support character references in single attribute values', - async function () { - assert.equal( - micromark(":abbr{title='a'b'}", options({abbr})), - '

' - ) - } - ) - - await t.test( - 'should support unknown character references in attribute values', - async function () { - assert.equal( - micromark(':abbr{title="a&somethingelse;b"}', options({abbr})), - '

' - ) - } - ) - - await t.test( - 'should not support non-terminated character references in unquoted attribute values', - async function () { - assert.equal( - micromark(':a{href=¶m}', options({'*': h})), - '

' - ) - } - ) - - await t.test( - 'should not support non-terminated character references in double quoted attribute values', - async function () { - assert.equal( - micromark(':a{href="¶m"}', options({'*': h})), - '

' - ) - } - ) - - await t.test( - 'should not support non-terminated character references in single quoted attribute values', - async function () { - assert.equal( - micromark(":a{href='¶m'}", options({'*': h})), - '

' - ) - } - ) - - await t.test('should support EOLs between attributes', async function () { - assert.equal( - micromark(':span{a\nb}', options({'*': h})), - '

' - ) - }) - - await t.test( - 'should support EOLs at the edges of attributes', - async function () { - assert.equal( - micromark(':span{\na\n}', options({'*': h})), - '

' - ) - } - ) - - await t.test('should support EOLs before initializer', async function () { - assert.equal( - micromark(':span{a\r= b}', options({'*': h})), - '

' - ) - }) - - await t.test('should support EOLs after initializer', async function () { - assert.equal( - micromark(':span{a=\r\nb}', options({'*': h})), - '

' - ) - }) - - await t.test( - 'should support EOLs between an unquoted attribute value and a next attribute name', - async function () { - assert.equal( - micromark(':span{a=b\nc}', options({'*': h})), - '

' - ) - } - ) - - await t.test( - 'should support EOLs in a double quoted attribute value', - async function () { - assert.equal( - micromark(':span{a="b\nc"}', options({'*': h})), - '

' - ) - } - ) - - await t.test( - 'should support EOLs in a single quoted attribute value', - async function () { - assert.equal( - micromark(":span{a='b\nc'}", options({'*': h})), - '

' - ) - } - ) - - await t.test('should support `id` shortcuts', async function () { - assert.equal( - micromark(':span{#a#b}', options({'*': h})), - '

' - ) - }) - - await t.test( - 'should support `id` shortcuts after `id` attributes', - async function () { - assert.equal( - micromark(':span{id=a id="b" #c#d}', options({'*': h})), - '

' - ) - } - ) - - await t.test('should support `class` shortcuts', async function () { - assert.equal( - micromark(':span{.a.b}', options({'*': h})), - '

' - ) - }) - - await t.test( - 'should support `class` shortcuts after `class` attributes', - async function () { - assert.equal( - micromark(':span{class=a class="b c" .d.e}', options({'*': h})), - '

' - ) - } - ) - - await t.test( - 'should support container directives in container directives', - async function () { - assert.equal( - micromark('::::div{.big}\n:::div{.small}\nText', options({'*': h})), - '
\n
\n

Text

\n
\n
' - ) - } - ) - - await t.test( - 'should support leaf directives in container directives', - async function () { - assert.equal( - micromark(':::div{.big}\n::hr{.small}', options({'*': h})), - '
\n
\n
' - ) - } - ) - - await t.test( - 'should support text directives in container directives', - async function () { - assert.equal( - micromark(':::div{.big}\n:b[Text]', options({'*': h})), - '
\n

Text

\n
' - ) - } - ) - - await t.test( - 'should support lists in container directives', - async function () { - assert.equal( - micromark(':::section\n* a\n:::', options({'*': h})), - '
\n
    \n
  • a
  • \n
\n
' - ) - } - ) - - await t.test( - 'should support lists w/ label brackets in container directives', - async function () { - assert.equal( - micromark(':::section[]\n* a\n:::', options({'*': h})), - '
\n
    \n
  • a
  • \n
\n
' - ) - } - ) - - await t.test( - 'should support lists w/ attribute braces in container directives', - async function () { - assert.equal( - micromark(':::section{}\n* a\n:::', options({'*': h})), - '
\n
    \n
  • a
  • \n
\n
' - ) - } - ) - - await t.test( - 'should support lazy containers in an unclosed container directive', - async function () { - assert.equal(micromark(':::i\n- +\na', options()), '') - } - ) -}) - -/** - * @this {CompileContext} - * @type {Handle} - */ -function abbr(d) { - if (d.type !== 'textDirective') return false - - this.tag('') - this.raw(d.label || '') - this.tag('') -} - -/** - * @this {CompileContext} - * @type {Handle} - */ -function youtube(d) { - const attributes = d.attributes || {} - const v = attributes.v - /** @type {string} */ - let key - - if (!v) return false - - const list = [ - 'src="https://www.youtube.com/embed/' + this.encode(v) + '"', - 'allowfullscreen' - ] - - if (d.label) { - list.push('title="' + this.encode(d.label) + '"') - } - - for (key in attributes) { - if (key !== 'v') { - list.push(this.encode(key) + '="' + this.encode(attributes[key]) + '"') - } - } - - this.tag('') -} - -/** - * @this {CompileContext} - * Context. - * @type {Handle} - * Handle. - * @returns {undefined} - * Nothing. - */ -function h(d) { - const content = d.content || d.label - const attributes = d.attributes || {} - /** @type {Array} */ - const list = [] - /** @type {string} */ - let key - - for (key in attributes) { - if (own.call(attributes, key)) { - list.push(this.encode(key) + '="' + this.encode(attributes[key]) + '"') - } - } - - this.tag('<' + d.name) - if (list.length > 0) this.tag(' ' + list.join(' ')) - this.tag('>') - - if (content) { - if (d.type === 'containerDirective') this.lineEndingIfNeeded() - this.raw(content) - if (d.type === 'containerDirective') this.lineEndingIfNeeded() - } - - if (!htmlVoidElements.includes(d.name)) this.tag('') -} - -/** - * @param {HtmlOptions | null | undefined} [options={}] - * HTML configuration (default: `{}`). - */ -function options(options) { - return { - allowDangerousHtml: true, - extensions: [directive()], - htmlExtensions: [directiveHtml(options)] - } -}