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: import table from markdown (#4881)
Mukund-Tandon9201cd634758
diff --git a/frontend/appflowy_flutter/assets/test/workspaces/markdowns/markdown_with_table.md b/frontend/appflowy_flutter/assets/test/workspaces/markdowns/markdown_with_table.mdnew file mode 100644index 0000000000..5998220774--- /dev/null+++ b/frontend/appflowy_flutter/assets/test/workspaces/markdowns/markdown_with_table.md@@ -0,0 +1,11 @@+# AppFlowy Test Markdown import with table++# Table++| S.No. | Column 2 |+| --- | --- |+| 1. | row 1 |+| 2. | row 2 |+| 3. | row 3 |+| 4. | row 4 |+| 5. | row 5 |\ No newline at end of filediff --git a/frontend/appflowy_flutter/integration_test/desktop/uncategorized/import_files_test.dart b/frontend/appflowy_flutter/integration_test/desktop/uncategorized/import_files_test.dartindex 58d8cc75be..8f356b8406 100644--- a/frontend/appflowy_flutter/integration_test/desktop/uncategorized/import_files_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/uncategorized/import_files_test.dart@@ -1,5 +1,6 @@import 'dart:io';+import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';import 'package:integration_test/integration_test.dart';@@ -44,5 +45,44 @@ void main() {tester.expectToSeePageName('test1');tester.expectToSeePageName('test2');});++ testWidgets('import markdown file with table', (tester) async {+ final context = await tester.initializeAppFlowy();+ await tester.tapGoButton();++ // expect to see a getting started page+ tester.expectToSeePageName(gettingStarted);++ await tester.tapAddViewButton();+ await tester.tapImportButton();++ const testFileName = 'markdown_with_table.md';+ final paths = <String>[];+ final str = await rootBundle.loadString(+ 'assets/test/workspaces/markdowns/$testFileName',+ );+ final path = p.join(context.applicationDataDirectory, testFileName);+ paths.add(path);+ File(path).writeAsStringSync(str);+ // mock get files+ mockPickFilePaths(+ paths: paths,+ );++ await tester.tapTextAndMarkdownButton();++ tester.expectToSeePageName('markdown_with_table');++ // expect to see all content of markdown file along with table+ await tester.openPage('markdown_with_table');++ final importedPageEditorState = tester.editor.getCurrentEditorState();+ expect(importedPageEditorState.getNodeAtPath([0])!.type,+ HeadingBlockKeys.type,);+ expect(importedPageEditorState.getNodeAtPath([2])!.type,+ HeadingBlockKeys.type,);+ expect(importedPageEditorState.getNodeAtPath([4])!.type,+ TableBlockKeys.type,);+ });});}diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dartindex 1c98b970f2..a6d8974921 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_data_pb_extension.dart@@ -59,11 +59,11 @@ extension DocumentDataPBFromTo on DocumentDataPB {// generate the metafinal childrenMap = <String, ChildrenPB>{};- blocks.forEach((key, value) {- final parentId = value.parentId;- if (parentId.isNotEmpty) {- childrenMap[parentId] ??= ChildrenPB.create();- childrenMap[parentId]!.children.add(value.id);+ blocks.values.where((e) => e.parentId.isNotEmpty).forEach((value) {+ final childrenId = blocks[value.parentId]?.childrenId;+ if (childrenId != null) {+ childrenMap[childrenId] ??= ChildrenPB.create();+ childrenMap[childrenId]!.children.add(value.id);}});final meta = MetaPB(childrenMap: childrenMap);