Yuki Takei пре 3 година
родитељ
комит
bb33e6bae6

+ 149 - 0
packages/app/remark-gfm.test.mjs

@@ -0,0 +1,149 @@
+import { remark } from 'remark';
+import remarkGfm from 'remark-gfm';
+
+const bigTable1 = String.raw`# Big Table 1
+
+| Key  | Value           |
+| ---- | --------------- |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+
+`;
+
+
+const bigTable2 = String.raw`# Big Table 2
+
+| Key  | Value           |
+| ---- | --------------- |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| ---- | --------------- |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| ---- | --------------- |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| ---- | --------------- |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+| ---- | --------------- |
+| k1   | v1              |
+| k2   | v2              |
+| k3   | v3              |
+| k4   | v4              |
+| k5   | v5              |
+| k6   | v6              |
+| k7   | v7              |
+| k8   | v8              |
+| k9   | v9              |
+| k10  | v10             |
+
+`;
+
+
+main();
+
+async function main() {
+  console.time('bigTable1 w/o gfm');
+  await remark()
+    .process(bigTable1);
+  console.timeEnd('bigTable1 w/o gfm');
+
+  console.time('bigTable1 w/  gfm');
+  await remark()
+    .use(remarkGfm)
+    .process(bigTable1);
+  console.timeEnd('bigTable1 w/  gfm');
+
+  console.time('bigTable2 w/o gfm');
+  await remark()
+    .process(bigTable2);
+  console.timeEnd('bigTable2 w/o gfm');
+
+  console.time('bigTable2 w/  gfm');
+  await remark()
+    .use(remarkGfm)
+    .process(bigTable2);
+  console.timeEnd('bigTable2 w/  gfm');
+
+}

+ 1 - 1
packages/remark-growi-directive/test/fixtures/leaf/input.md

@@ -8,4 +8,4 @@ $a[b](c)
 
 
 $a[b *c* d **e**]
 $a[b *c* d **e**]
 
 
-$a(#b.c.d id=e class="f g" h="i & j k")
+$a(#b.c.d .f.g h="i & j k")

+ 1 - 1
packages/remark-growi-directive/test/fixtures/leaf/output.md

@@ -8,4 +8,4 @@ $a[b](c)
 
 
 $a[b *c* d **e**]
 $a[b *c* d **e**]
 
 
-$a(#e .c.d.f.g h="i & j k")
+$a(#b.c.d .f.g h="i & j k")

+ 5 - 5
packages/remark-growi-directive/test/fixtures/leaf/tree.json

@@ -232,8 +232,8 @@
       "type": "leafGrowiPluginDirective",
       "type": "leafGrowiPluginDirective",
       "name": "a",
       "name": "a",
       "attributes": {
       "attributes": {
-        "id": "e",
-        "class": "c d f g",
+        "#b.c.d": "",
+        ".f.g": "",
         "h": "i & j k"
         "h": "i & j k"
       },
       },
       "children": [],
       "children": [],
@@ -245,8 +245,8 @@
         },
         },
         "end": {
         "end": {
           "line": 11,
           "line": 11,
-          "column": 44,
-          "offset": 90
+          "column": 32,
+          "offset": 78
         }
         }
       }
       }
     }
     }
@@ -260,7 +260,7 @@
     "end": {
     "end": {
       "line": 12,
       "line": 12,
       "column": 1,
       "column": 1,
-      "offset": 91
+      "offset": 79
     }
     }
   }
   }
 }
 }

+ 1 - 1
packages/remark-growi-directive/test/fixtures/text/input.md

@@ -3,5 +3,5 @@ One $a, two $a[b], three $a(b), four $a[b](c).
 $a[b *c*
 $a[b *c*
 d **e**].
 d **e**].
 
 
-$a(#b.c.d id=e class="f g" h="i & j
+$a(#b.c.d .f.g h="i & j
 k").
 k").

+ 1 - 1
packages/remark-growi-directive/test/fixtures/text/output.md

@@ -3,5 +3,5 @@ One $a, two $a[b], three $a(b), four $a[b](c).
 $a[b *c*
 $a[b *c*
 d **e**].
 d **e**].
 
 
-$a(#e .c.d.f.g h="i & j
+$a(#b.c.d .f.g h="i & j
 k").
 k").

+ 7 - 7
packages/remark-growi-directive/test/fixtures/text/tree.json

@@ -365,8 +365,8 @@
           "type": "textGrowiPluginDirective",
           "type": "textGrowiPluginDirective",
           "name": "a",
           "name": "a",
           "attributes": {
           "attributes": {
-            "id": "e",
-            "class": "c d f g",
+            "#b.c.d": "",
+            ".f.g": "",
             "h": "i & j\nk"
             "h": "i & j\nk"
           },
           },
           "children": [],
           "children": [],
@@ -379,7 +379,7 @@
             "end": {
             "end": {
               "line": 7,
               "line": 7,
               "column": 4,
               "column": 4,
-              "offset": 111
+              "offset": 99
             }
             }
           }
           }
         },
         },
@@ -390,12 +390,12 @@
             "start": {
             "start": {
               "line": 7,
               "line": 7,
               "column": 4,
               "column": 4,
-              "offset": 111
+              "offset": 99
             },
             },
             "end": {
             "end": {
               "line": 7,
               "line": 7,
               "column": 5,
               "column": 5,
-              "offset": 112
+              "offset": 100
             }
             }
           }
           }
         }
         }
@@ -409,7 +409,7 @@
         "end": {
         "end": {
           "line": 7,
           "line": 7,
           "column": 5,
           "column": 5,
-          "offset": 112
+          "offset": 100
         }
         }
       }
       }
     }
     }
@@ -423,7 +423,7 @@
     "end": {
     "end": {
       "line": 8,
       "line": 8,
       "column": 1,
       "column": 1,
-      "offset": 113
+      "offset": 101
     }
     }
   }
   }
 }
 }

+ 18 - 8
packages/remark-growi-directive/test/mdast-util-growi-directive.test.js

@@ -119,6 +119,14 @@ test('markdown -> mdast', (t) => {
     'should support content in a label',
     'should support content in a label',
   );
   );
 
 
+  const hoge = removePosition(
+    fromMarkdown('x $a(#b.c.d e=f g="h&i&unknown;j")', {
+      extensions: [directive()],
+      mdastExtensions: [directiveFromMarkdown],
+    }),
+    true,
+  );
+
   t.deepEqual(
   t.deepEqual(
     removePosition(
     removePosition(
       fromMarkdown('x $a(#b.c.d e=f g="h&i&unknown;j")', {
       fromMarkdown('x $a(#b.c.d e=f g="h&i&unknown;j")', {
@@ -138,7 +146,7 @@ test('markdown -> mdast', (t) => {
               type: DirectiveType.Text,
               type: DirectiveType.Text,
               name: 'a',
               name: 'a',
               attributes: {
               attributes: {
-                id: 'b', class: 'c d', e: 'f', g: 'h&i&unknown;j',
+                '#b.c.d': '', e: 'f', g: 'h&i&unknown;j',
               },
               },
               children: [],
               children: [],
             },
             },
@@ -307,7 +315,7 @@ test('mdast -> markdown', (t) => {
           {
           {
             type: DirectiveType.Text,
             type: DirectiveType.Text,
             name: 'b',
             name: 'b',
-            attributes: { class: 'a b\nc', id: 'd', key: 'value' },
+            attributes: { '#d': '', '.a.b.c': '', key: 'value' },
             children: [],
             children: [],
           },
           },
           { type: 'text', value: ' k.' },
           { type: 'text', value: ' k.' },
@@ -316,7 +324,7 @@ test('mdast -> markdown', (t) => {
       { extensions: [directiveToMarkdown] },
       { extensions: [directiveToMarkdown] },
     ),
     ),
     'a $b(#d .a.b.c key="value") k.\n',
     'a $b(#d .a.b.c key="value") k.\n',
-    'should serialize a directive (text) w/ `id`, `class` attributes',
+    'should serialize a directive (text) w/ hash, dot notation attributes',
   );
   );
 
 
   t.deepEqual(
   t.deepEqual(
@@ -391,7 +399,7 @@ test('mdast -> markdown', (t) => {
           {
           {
             type: DirectiveType.Text,
             type: DirectiveType.Text,
             name: 'b',
             name: 'b',
-            attributes: { class: 'c.d e<f' },
+            attributes: { 'c.d': '', 'e<f': '' },
             children: [],
             children: [],
           },
           },
           { type: 'text', value: ' g.' },
           { type: 'text', value: ' g.' },
@@ -399,7 +407,7 @@ test('mdast -> markdown', (t) => {
       },
       },
       { extensions: [directiveToMarkdown] },
       { extensions: [directiveToMarkdown] },
     ),
     ),
-    'a $b(class="c.d e<f") g.\n',
+    'a $b(c.d e<f) g.\n',
     'should not use the `class` shortcut if impossible characters exist',
     'should not use the `class` shortcut if impossible characters exist',
   );
   );
 
 
@@ -412,7 +420,9 @@ test('mdast -> markdown', (t) => {
           {
           {
             type: DirectiveType.Text,
             type: DirectiveType.Text,
             name: 'b',
             name: 'b',
-            attributes: { class: 'c.d e f<g hij' },
+            attributes: {
+              'c.d': '', e: '', 'f<g': '', hij: '',
+            },
             children: [],
             children: [],
           },
           },
           { type: 'text', value: ' k.' },
           { type: 'text', value: ' k.' },
@@ -420,7 +430,7 @@ test('mdast -> markdown', (t) => {
       },
       },
       { extensions: [directiveToMarkdown] },
       { extensions: [directiveToMarkdown] },
     ),
     ),
-    'a $b(.e.hij class="c.d f<g") k.\n',
+    'a $b(c.d e f<g hij) k.\n',
     'should not use the `class` shortcut if impossible characters exist (but should use it for classes that don’t)',
     'should not use the `class` shortcut if impossible characters exist (but should use it for classes that don’t)',
   );
   );
 
 
@@ -485,7 +495,7 @@ test('mdast -> markdown', (t) => {
       {
       {
         type: DirectiveType.Leaf,
         type: DirectiveType.Leaf,
         name: 'a',
         name: 'a',
-        attributes: { id: 'b', class: 'c d', key: 'e\nf' },
+        attributes: { '#b': '', '.c.d': '', key: 'e\nf' },
         children: [],
         children: [],
       },
       },
       { extensions: [directiveToMarkdown] },
       { extensions: [directiveToMarkdown] },

+ 24 - 30
packages/remark-growi-directive/test/micromark-extension-growi-directive.test.js

@@ -231,39 +231,39 @@ test('micromark-extension-directive (syntax)', (t) => {
     );
     );
 
 
     t.equal(
     t.equal(
-      micromark('$a(..b)', options()),
-      '<p>(..b)</p>',
-      'should not support an empty shortcut (`.`)',
+      micromark('a $a(..b)', options()),
+      '<p>a </p>',
+      'should support attrs which starts w/ continuous dots',
     );
     );
 
 
     t.equal(
     t.equal(
-      micromark('$a(.#b)', options()),
-      '<p>(.#b)</p>',
-      'should not support an empty shortcut (`#`)',
+      micromark('a $a(.#b)', options()),
+      '<p>a </p>',
+      'should support attrs which start w/ `#`',
     );
     );
 
 
     t.equal(
     t.equal(
-      micromark('$a(.)', options()),
-      '<p>(.)</p>',
-      'should not support an empty shortcut (`}`)',
+      micromark('a $a(.)', options()),
+      '<p>a </p>',
+      'should support attrs w/ (`.`)',
     );
     );
 
 
     t.equal(
     t.equal(
-      micromark('$a(.a=b)', options()),
-      '<p>(.a=b)</p>',
-      'should not support certain characters in shortcuts (`=`)',
+      micromark('a $a(.a=b)', options()),
+      '<p>a </p>',
+      'should support with the attr `(.a=b)`',
     );
     );
 
 
     t.equal(
     t.equal(
-      micromark('$a(.a"b)', options()),
-      '<p>(.a&quot;b)</p>',
-      'should not support certain characters in shortcuts (`"`)',
+      micromark('a $a(.a"b)', options()),
+      '<p>a </p>',
+      'should support with the attr `(.a"b)`',
     );
     );
 
 
     t.equal(
     t.equal(
-      micromark('$a(.a<b)', options()),
-      '<p>(.a&lt;b)</p>',
-      'should not support certain characters in shortcuts (`<`)',
+      micromark('a $a(.a<b)', options()),
+      '<p>a </p>',
+      'should support with the attr `(.a<b)`',
     );
     );
 
 
     t.equal(
     t.equal(
@@ -1002,26 +1002,20 @@ test('content', (t) => {
 
 
   t.equal(
   t.equal(
     micromark('a $span(#a#b)', options({ '*': h })),
     micromark('a $span(#a#b)', options({ '*': h })),
-    '<p>a <span id="b"></span></p>',
-    'should support `id` shortcuts',
+    '<p>a <span #a#b=""></span></p>',
+    'should support attrs which contains `#` (1)',
   );
   );
 
 
   t.equal(
   t.equal(
     micromark('a $span(id=a id="b" #c#d)', options({ '*': h })),
     micromark('a $span(id=a id="b" #c#d)', options({ '*': h })),
-    '<p>a <span id="d"></span></p>',
-    'should support `id` shortcuts after `id` attributes',
+    '<p>a <span id="b" #c#d=""></span></p>',
+    'should support attrs which contains `#` (2)',
   );
   );
 
 
   t.equal(
   t.equal(
     micromark('a $span(.a.b)', options({ '*': h })),
     micromark('a $span(.a.b)', options({ '*': h })),
-    '<p>a <span class="a b"></span></p>',
-    'should support `class` shortcuts',
-  );
-
-  t.equal(
-    micromark('a $span(class=a class="b c" .d.e)', options({ '*': h })),
-    '<p>a <span class="a b c d e"></span></p>',
-    'should support `class` shortcuts after `class` attributes',
+    '<p>a <span .a.b=""></span></p>',
+    'should support attrs with dot notation',
   );
   );
 
 
   t.test('spec for growi plugin', (t) => {
   t.test('spec for growi plugin', (t) => {

+ 2 - 0
packages/remark-growi-directive/test/remark-growi-directive.test.js

@@ -2,8 +2,10 @@
  * @typedef {import('mdast').Root} Root
  * @typedef {import('mdast').Root} Root
  */
  */
 
 
+
 import fs from 'node:fs';
 import fs from 'node:fs';
 import path from 'node:path';
 import path from 'node:path';
+import util from 'util';
 
 
 import { isHidden } from 'is-hidden';
 import { isHidden } from 'is-hidden';
 import { remark } from 'remark';
 import { remark } from 'remark';