Skip to content

Commit

Permalink
feat: add markdown divider encoder parser (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishjohnson authored Jan 8, 2024
1 parent ca5b589 commit c8ba248
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/src/plugins/markdown/document_markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -43,6 +42,7 @@ String documentToMarkdown(
const HeadingNodeParser(),
const ImageNodeParser(),
const TableNodeParser(),
const DividerNodeParser(),
],
).encode(document);
}
Expand Down
13 changes: 13 additions & 0 deletions lib/src/plugins/markdown/encoder/parser/divider_node_parser.dart
Original file line number Diff line number Diff line change
@@ -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';
}
}
10 changes: 6 additions & 4 deletions lib/src/plugins/markdown/encoder/parser/parser.dart
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 1 addition & 3 deletions lib/src/plugins/plugins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 1 addition & 0 deletions test/plugins/markdown/document_markdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ const markdownDocumentEncoded = """# Heading 1
## Heading 2
### Heading 3
---
""";
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions test/plugins/markdown/encoder/parser/divider_node_parser_test.dart
Original file line number Diff line number Diff line change
@@ -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');
});
});
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit c8ba248

Please sign in to comment.