diff --git a/lib/src/plugins/markdown/document_markdown.dart b/lib/src/plugins/markdown/document_markdown.dart index 6d971503d..87149cf7b 100644 --- a/lib/src/plugins/markdown/document_markdown.dart +++ b/lib/src/plugins/markdown/document_markdown.dart @@ -6,7 +6,6 @@ import 'package:appflowy_editor/src/core/document/document.dart'; import 'package:appflowy_editor/src/plugins/markdown/decoder/document_markdown_decoder.dart'; import 'package:appflowy_editor/src/plugins/markdown/decoder/parser/custom_node_parser.dart'; import 'package:appflowy_editor/src/plugins/markdown/encoder/document_markdown_encoder.dart'; -import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/image_node_parser.dart'; import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/parser.dart'; import 'package:markdown/markdown.dart' as md; @@ -43,6 +42,7 @@ String documentToMarkdown( const HeadingNodeParser(), const ImageNodeParser(), const TableNodeParser(), + const DividerNodeParser(), ], ).encode(document); } diff --git a/lib/src/plugins/markdown/encoder/parser/divider_node_parser.dart b/lib/src/plugins/markdown/encoder/parser/divider_node_parser.dart new file mode 100644 index 000000000..808d0e863 --- /dev/null +++ b/lib/src/plugins/markdown/encoder/parser/divider_node_parser.dart @@ -0,0 +1,13 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; + +class DividerNodeParser extends NodeParser { + const DividerNodeParser(); + + @override + String get id => DividerBlockKeys.type; + + @override + String transform(Node node, DocumentMarkdownEncoder? encoder) { + return '---\n'; + } +} diff --git a/lib/src/plugins/markdown/encoder/parser/parser.dart b/lib/src/plugins/markdown/encoder/parser/parser.dart index f097697e1..a3d3dbbcb 100644 --- a/lib/src/plugins/markdown/encoder/parser/parser.dart +++ b/lib/src/plugins/markdown/encoder/parser/parser.dart @@ -1,9 +1,11 @@ export 'bulleted_list_node_parser.dart'; +export 'code_block_node_parser.dart'; +export 'divider_node_parser.dart'; export 'heading_node_parser.dart'; +export 'image_node_parser.dart'; export 'node_parser.dart'; -export 'quote_node_parser.dart'; export 'numbered_list_node_parser.dart'; -export 'todo_list_node_parser.dart'; -export 'text_node_parser.dart'; -export 'code_block_node_parser.dart'; +export 'quote_node_parser.dart'; export 'table_node_parser.dart'; +export 'text_node_parser.dart'; +export 'todo_list_node_parser.dart'; diff --git a/lib/src/plugins/plugins.dart b/lib/src/plugins/plugins.dart index a26347b24..1bf0ebc80 100644 --- a/lib/src/plugins/plugins.dart +++ b/lib/src/plugins/plugins.dart @@ -7,7 +7,5 @@ export 'markdown/decoder/delta_markdown_decoder.dart'; export 'markdown/document_markdown.dart'; export 'markdown/encoder/delta_markdown_encoder.dart'; export 'markdown/encoder/document_markdown_encoder.dart'; -export 'markdown/encoder/parser/image_node_parser.dart'; -export 'markdown/encoder/parser/node_parser.dart'; -export 'markdown/encoder/parser/text_node_parser.dart'; +export 'markdown/encoder/parser/parser.dart'; export 'quill_delta/quill_delta_encoder.dart'; diff --git a/test/plugins/markdown/document_markdown_test.dart b/test/plugins/markdown/document_markdown_test.dart index 4a3c63e2b..8a6153c6e 100644 --- a/test/plugins/markdown/document_markdown_test.dart +++ b/test/plugins/markdown/document_markdown_test.dart @@ -98,4 +98,5 @@ const markdownDocumentEncoded = """# Heading 1 ## Heading 2 ### Heading 3 +--- """; diff --git a/test/plugins/markdown/encoder/document_markdown_encoder_test.dart b/test/plugins/markdown/encoder/document_markdown_encoder_test.dart index a3d43685c..7d0504b90 100644 --- a/test/plugins/markdown/encoder/document_markdown_encoder_test.dart +++ b/test/plugins/markdown/encoder/document_markdown_encoder_test.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/parser.dart'; import 'package:flutter_test/flutter_test.dart'; void main() async { diff --git a/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart b/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart new file mode 100644 index 000000000..075a9cd08 --- /dev/null +++ b/test/plugins/markdown/encoder/parser/divider_node_parser_test.dart @@ -0,0 +1,20 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() async { + group('divider_node_parser.dart', () { + test('parser divider node', () { + final node = Node( + type: DividerBlockKeys.type, + ); + + final result = const DividerNodeParser().transform(node, null); + expect(result, '---\n'); + }); + + test('DividerNodeParser id getter', () { + const imageNodeParser = DividerNodeParser(); + expect(imageNodeParser.id, 'divider'); + }); + }); +} diff --git a/test/plugins/markdown/encoder/parser/text_node_parser_test.dart b/test/plugins/markdown/encoder/parser/text_node_parser_test.dart index 0e828803a..e97746bf5 100644 --- a/test/plugins/markdown/encoder/parser/text_node_parser_test.dart +++ b/test/plugins/markdown/encoder/parser/text_node_parser_test.dart @@ -1,5 +1,4 @@ import 'package:appflowy_editor/appflowy_editor.dart'; -import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/parser.dart'; import 'package:flutter_test/flutter_test.dart'; void main() async {