diff --git a/plugins/notion/src/blocksToHTML.ts b/plugins/notion/src/blocksToHTML.ts index 50d02010e..f89c63edd 100644 --- a/plugins/notion/src/blocksToHTML.ts +++ b/plugins/notion/src/blocksToHTML.ts @@ -98,6 +98,28 @@ export function blocksToHtml(blocks: BlockObjectResponse[]) { case "code": htmlContent += `
${richTextToHTML(block.code.rich_text)}
` break + case "table": + htmlContent += `` + break + case "table_row": + if (blocks[i - 1]?.type === "table") { + htmlContent += `` + block.table_row.cells.forEach((cell) => { + htmlContent += `` + }) + htmlContent += `` + } else { + htmlContent += `` + block.table_row.cells.forEach((cell) => { + htmlContent += `` + }) + htmlContent += `` + } + + if (blocks[i + 1]?.type !== "table_row") { + htmlContent += `
${richTextToHTML(cell)}
${richTextToHTML(cell)}
` + } + break case "video": { if (block.video.type !== "external") { break @@ -116,6 +138,5 @@ export function blocksToHtml(blocks: BlockObjectResponse[]) { break } } - return htmlContent } diff --git a/plugins/notion/src/notion.ts b/plugins/notion/src/notion.ts index d9cbf8da3..8dc747796 100644 --- a/plugins/notion/src/notion.ts +++ b/plugins/notion/src/notion.ts @@ -533,6 +533,19 @@ export interface SynchronizeResult extends SyncStatus { status: "success" | "completed_with_errors" } +async function getBlockChildrenIterator(blockId: string) { + assert(notion, "Notion client is not initialized") + const blocksIterator = iteratePaginatedAPI(notion.blocks.children.list, { + block_id: blockId, + }) + const blocks: BlockObjectResponse[] = [] + for await (const block of blocksIterator) { + if (!isFullBlock(block)) continue + blocks.push(block) + } + return blocks +} + async function getPageBlocksAsRichText(pageId: string) { assert(notion, "Notion client is not initialized") @@ -544,6 +557,11 @@ async function getPageBlocksAsRichText(pageId: string) { for await (const block of blocksIterator) { if (!isFullBlock(block)) continue blocks.push(block) + + if (block.type === "table") { + const tableRows = await getBlockChildrenIterator(block.id) + blocks.push(...tableRows) + } } assert(blocks.every(isFullBlock), "Response is not a full block")