diff --git a/server/utils/NotionConverter.ts b/server/utils/NotionConverter.ts index 578a8cf01c..44dd197ec3 100644 --- a/server/utils/NotionConverter.ts +++ b/server/utils/NotionConverter.ts @@ -26,7 +26,7 @@ import isArray from "lodash/isArray"; import { MentionType, ProsemirrorData } from "@shared/types"; import Logger from "@server/logging/Logger"; -export type NotionBlock = BlockObjectResponse & { +export type NotionBlock = T & { children: NotionBlock[]; }; @@ -88,6 +88,10 @@ export class NotionConverter { let wrappingList; const children = [] as ProsemirrorData[]; + if (!item.children) { + return []; + } + for (const child of item.children) { const mapped = mapChild(child); if (!mapped) { @@ -137,6 +141,10 @@ export class NotionConverter { children.push(...(isArray(mapped) ? mapped : [mapped])); } + if (wrappingList) { + children.push(wrappingList); + } + return children; } @@ -165,7 +173,9 @@ export class NotionConverter { return undefined; } - private static bulleted_list_item(item: BulletedListItemBlockObjectResponse) { + private static bulleted_list_item( + item: NotionBlock + ) { return { type: "list_item", content: [ @@ -173,6 +183,7 @@ export class NotionConverter { type: "paragraph", content: item.bulleted_list_item.rich_text.map(this.rich_text), }, + ...this.mapChildren(item), ], }; } @@ -192,7 +203,9 @@ export class NotionConverter { }; } - private static numbered_list_item(item: NumberedListItemBlockObjectResponse) { + private static numbered_list_item( + item: NotionBlock + ) { return { type: "list_item", content: [ @@ -200,6 +213,7 @@ export class NotionConverter { type: "paragraph", content: item.numbered_list_item.rich_text.map(this.rich_text), }, + ...this.mapChildren(item), ], }; } @@ -414,7 +428,7 @@ export class NotionConverter { }; } - private static to_do(item: ToDoBlockObjectResponse) { + private static to_do(item: NotionBlock) { return { type: "checkbox_item", attrs: { @@ -425,6 +439,7 @@ export class NotionConverter { type: "paragraph", content: item.to_do.rich_text.map(this.rich_text), }, + ...this.mapChildren(item), ], }; } diff --git a/server/utils/__snapshots__/NotionConverter.test.ts.snap b/server/utils/__snapshots__/NotionConverter.test.ts.snap index 93ea0a4356..39b8c42264 100644 --- a/server/utils/__snapshots__/NotionConverter.test.ts.snap +++ b/server/utils/__snapshots__/NotionConverter.test.ts.snap @@ -102,6 +102,46 @@ exports[`NotionConverter converts a page 1`] = ` ], "type": "paragraph", }, + { + "content": [ + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Bullet list item 2.1", + "type": "text", + }, + ], + "type": "paragraph", + }, + { + "content": [ + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Ordered list item 2.1.1", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "list_item", + }, + ], + "type": "ordered_list", + }, + ], + "type": "list_item", + }, + ], + "type": "bullet_list", + }, ], "type": "list_item", }, @@ -970,6 +1010,76 @@ exports[`NotionConverter converts a page 1`] = ` ], "type": "paragraph", }, + { + "content": [ + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Numbered list item 2.1", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "list_item", + }, + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Numbered list item 2.2", + "type": "text", + }, + ], + "type": "paragraph", + }, + { + "content": [ + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Bullet list item 2.2.1", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "list_item", + }, + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Bullet list item 2.2.2", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "list_item", + }, + ], + "type": "bullet_list", + }, + ], + "type": "list_item", + }, + ], + "type": "ordered_list", + }, ], "type": "list_item", }, @@ -1326,6 +1436,92 @@ exports[`NotionConverter converts a page 1`] = ` ], "type": "paragraph", }, + { + "content": [ + { + "attrs": { + "checked": false, + }, + "content": [ + { + "content": [ + { + "marks": [], + "text": "Todo item 2.1", + "type": "text", + }, + ], + "type": "paragraph", + }, + { + "content": [ + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "Numbered item 2.1.1", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "list_item", + }, + { + "content": [ + { + "content": [ + { + "marks": [], + "text": "bulleted item 2.1.2", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "list_item", + }, + ], + "type": "ordered_list", + }, + ], + "type": "checkbox_item", + }, + { + "attrs": { + "checked": false, + }, + "content": [ + { + "content": [ + { + "marks": [], + "text": "Todo item 2.2", + "type": "text", + }, + ], + "type": "paragraph", + }, + { + "content": [ + { + "marks": [], + "text": "Nested content inside todo item 2.2.", + "type": "text", + }, + ], + "type": "paragraph", + }, + ], + "type": "checkbox_item", + }, + ], + "type": "checkbox_list", + }, ], "type": "checkbox_item", },