From 114968f2eeb2c07ab56b2ba1d2cc5e42d5e9193a Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 6 Dec 2022 17:48:00 +0800 Subject: [PATCH] fix: markdown decoder and encoder test error --- .../decoder/document_markdown_decoder.dart | 2 +- .../encoder/parser/divider_node_parser_test.dart | 15 +++++++++++++++ .../encoder/parser/text_node_parser_test.dart | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart index 05b8c4a1ff..fa12159106 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart @@ -80,7 +80,7 @@ class DocumentMarkdownDecoder extends Converter { BuiltInAttributeKey.subtype: BuiltInAttributeKey.quote, }, ); - } else if (RegExp(r'^-*').stringMatch(text) == text) { + } else if (text.isNotEmpty && RegExp(r'^-*').stringMatch(text) == text) { return Node(type: 'divider'); } diff --git a/frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart new file mode 100644 index 0000000000..f4cb580684 --- /dev/null +++ b/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'); + }); + }); +} diff --git a/frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/text_node_parser_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/text_node_parser_test.dart index 0d7c540a2b..4932dbde6f 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/plugins/markdown/encoder/parser/text_node_parser_test.dart +++ b/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```');