Closed GorvGoyl closed 1 year ago
current workaround
n2m.setCustomTransformer("synced_block", async (block) => {
const syncedBlock = block as SyncedBlockBlockObjectResponse;
const originalSyncedBlockId =
syncedBlock.synced_block.synced_from?.block_id;
const isReferenceSyncedBlock = !!originalSyncedBlockId;
// check if it's a 'reference synced block'
if (isReferenceSyncedBlock) {
const mdBlocks = await n2m.pageToMarkdown(originalSyncedBlockId);
const mdString = n2m.toMarkdownString(mdBlocks);
return mdString;
} else {
return ""; // 'original synced blocks' are handled like normal blocks by n2m so avoid rendering it twice
}
});
Nevermind it's working again without setCustomTransformer
of synced block.
This is my workaround:
/**
* Replacing synced blocks is returning either the synced block, or
* the first child of the synced block, and keep going until you reach
* a non-synced block.
*/
const replaceSyncedBlockWithTarget = async (
block: NotionBlock,
client: Client
): Promise<NotionBlock> => {
if (block.type !== "synced_block") {
return block;
}
const synced_from = block?.synced_block?.synced_from?.block_id;
if (synced_from) {
const syncedBlock = await client.blocks.retrieve({ block_id: synced_from });
return await replaceSyncedBlockWithTarget(
syncedBlock as NotionBlock,
client
);
}
const children = await client.blocks.children.list({ block_id: block.id });
if (children.results.length === 0) {
return block;
}
return await replaceSyncedBlockWithTarget(
children.results[0] as NotionBlock,
client
);
};
Please add support for reference synced blocks as well. Currently, these are silently ignored in output. original synced blocks are working fine though