From 9d74e27cecfcf15c45c64df8df7f8b4261ba223c Mon Sep 17 00:00:00 2001 From: Souvik Kar Mahapatra Date: Wed, 17 May 2023 03:18:25 +0530 Subject: [PATCH] fix: synced blocks custom transformer produces double output #62 --- src/notion-to-md.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/notion-to-md.ts b/src/notion-to-md.ts index be3d27a..f75c6fd 100644 --- a/src/notion-to-md.ts +++ b/src/notion-to-md.ts @@ -187,7 +187,7 @@ export class NotionToMarkdown { if (!blocks) return mdBlocks; for (let i = 0; i < blocks.length; i++) { - let block = blocks[i]; + let block: ListBlockChildrenResponseResult = blocks[i]; if ("has_children" in block && block.has_children) { // Get children of this block. @@ -206,12 +206,19 @@ export class NotionToMarkdown { }); // Recursively call blocksToMarkdown to get children of this block. - let l = mdBlocks.length; - await this.blocksToMarkdown( - child_blocks, - totalPage, - mdBlocks[l - 1].children - ); + // check for custom transformer before parsing child + if ( + !(block.type in this.customTransformers) && + !this.customTransformers[block.type] + ) { + let l = mdBlocks.length; + await this.blocksToMarkdown( + child_blocks, + totalPage, + mdBlocks[l - 1].children + ); + } + continue; }