浏览代码

fix: markdown decoder and encoder test error

Lucas.Xu 2 年之前
父节点
当前提交
114968f2ee

+ 1 - 1
frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart

@@ -80,7 +80,7 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {
           BuiltInAttributeKey.subtype: BuiltInAttributeKey.quote,
         },
       );
-    } else if (RegExp(r'^-*').stringMatch(text) == text) {
+    } else if (text.isNotEmpty && RegExp(r'^-*').stringMatch(text) == text) {
       return Node(type: 'divider');
     }
 

+ 15 - 0
frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart

@@ -0,0 +1,15 @@
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/divider_node_parser.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() async {
+  group('divider_node_parser.dart', () {
+    test('parser divider node', () {
+      final node = Node(
+        type: 'divider',
+      );
+      final result = const DividerNodeParser().transform(node);
+      expect(result, '---\n');
+    });
+  });
+}

+ 1 - 1
frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/text_node_parser_test.dart

@@ -86,7 +86,7 @@ void main() async {
       final node = TextNode(
         delta: Delta(operations: [TextInsert(text)]),
         attributes: {
-          BuiltInAttributeKey.subtype: 'code-block',
+          BuiltInAttributeKey.subtype: 'code_block',
         },
       );
       expect(const TextNodeParser().transform(node), '```\n$text\n```');