Просмотр исходного кода

WIP: parse leaf directive with single dollar sign

Yuki Takei 3 лет назад
Родитель
Сommit
524c94b4fe

+ 1 - 1
packages/remark-growi-plugin/src/mdast-util-growi-plugin/index.js

@@ -385,7 +385,7 @@ function fence(node) {
     size += 3;
   }
   else if (node.type === 'leafGrowiPluginDirective') {
-    size = 2;
+    size = 1;
   }
   else {
     size = 1;

+ 40 - 22
packages/remark-growi-plugin/src/micromark-extension-growi-plugin/lib/directive-leaf.js

@@ -27,37 +27,55 @@ function tokenizeDirectiveLeaf(effects, ok, nok) {
 
   return start;
 
+  // /** @type {State} */
+  // function start(code) {
+  //   assert(code === codes.dollarSign, 'expected `$`');
+  //   effects.enter('directiveLeaf');
+  //   effects.enter('directiveLeafSequence');
+  //   effects.consume(code);
+  //   return inStart;
+  // }
+
+  // /** @type {State} */
+  // function inStart(code) {
+  //   if (code === codes.dollarSign) {
+  //     effects.consume(code);
+  //     effects.exit('directiveLeafSequence');
+  //     return factoryName.call(
+  //       self,
+  //       effects,
+  //       afterName,
+  //       nok,
+  //       'directiveLeafName',
+  //     );
+  //   }
+
+  //   return nok(code);
+  // }
+
+  // /** @type {State} */
+  // function afterName(code) {
+  //   return code === codes.leftSquareBracket
+  //     ? effects.attempt(label, afterLabel, afterLabel)(code)
+  //     : afterLabel(code);
+  // }
+
   /** @type {State} */
   function start(code) {
     assert(code === codes.dollarSign, 'expected `$`');
     effects.enter('directiveLeaf');
-    effects.enter('directiveLeafSequence');
     effects.consume(code);
-    return inStart;
-  }
-
-  /** @type {State} */
-  function inStart(code) {
-    if (code === codes.dollarSign) {
-      effects.consume(code);
-      effects.exit('directiveLeafSequence');
-      return factoryName.call(
-        self,
-        effects,
-        afterName,
-        nok,
-        'directiveLeafName',
-      );
-    }
-
-    return nok(code);
+    return factoryName.call(self, effects, afterName, nok, 'directiveLeafName');
   }
 
   /** @type {State} */
   function afterName(code) {
-    return code === codes.leftSquareBracket
-      ? effects.attempt(label, afterLabel, afterLabel)(code)
-      : afterLabel(code);
+    // eslint-disable-next-line no-nested-ternary
+    return code === codes.dollarSign
+      ? nok(code)
+      : code === codes.leftSquareBracket
+        ? effects.attempt(label, afterLabel, afterLabel)(code)
+        : afterLabel(code);
   }
 
   /** @type {State} */