Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: add missing markdown converter for code block and divider
Lucas.Xu29952bc7fdf0
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.dartindex 257cfabb28..05b8c4a1ff 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,6 +80,8 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {BuiltInAttributeKey.subtype: BuiltInAttributeKey.quote,},);+ } else if (RegExp(r'^-*').stringMatch(text) == text) {+ return Node(type: 'divider');}if (text.isNotEmpty) {diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/document_markdown_encoder.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/document_markdown_encoder.dartindex 52c2bd3756..5a666bd443 100644--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/document_markdown_encoder.dart+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/document_markdown_encoder.dart@@ -1,6 +1,7 @@import 'dart:convert';import 'package:appflowy_editor/src/core/document/document.dart';+import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/divider_node_parser.dart';import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/image_node_parser.dart';import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/node_parser.dart';import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/text_node_parser.dart';@@ -10,6 +11,7 @@ class DocumentMarkdownEncoder extends Converter<Document, String> {this.parsers = const [TextNodeParser(),ImageNodeParser(),+ DividerNodeParser(),],});diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/divider_node_parser.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/divider_node_parser.dartnew file mode 100644index 0000000000..c9742fbd60--- /dev/null+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/divider_node_parser.dart@@ -0,0 +1,14 @@+import 'package:appflowy_editor/src/core/document/node.dart';+import 'package:appflowy_editor/src/plugins/markdown/encoder/parser/node_parser.dart';++class DividerNodeParser extends NodeParser {+ const DividerNodeParser();++ @override+ String get id => 'divider';++ @override+ String transform(Node node) {+ return '---\n';+ }+}diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/text_node_parser.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/text_node_parser.dartindex 8857310876..f6532c91d1 100644--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/text_node_parser.dart+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/plugins/markdown/encoder/parser/text_node_parser.dart@@ -40,7 +40,7 @@ class TextNodeParser extends NodeParser {}} else if (subtype == 'quote') {result = '> $markdown';- } else if (subtype == 'code-block') {+ } else if (subtype == 'code_block') {result = '```\n$markdown\n```';} else if (subtype == 'bulleted-list') {result = '* $markdown';