souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.08k stars 89 forks source link

Children blocks with custom transformers are not included in the output of blocksToMarkdown #98

Open andrew-polk opened 1 year ago

andrew-polk commented 1 year ago

This recent change broke all children with custom transformers when using blocksToMarkdown.

I understand the change was made to prevent some duplicate markdown from being created (#62), but I think a different solution is needed.

Consider the simple use case of a numbered list with sub items.

  1. One
    1. Sub one

If I call blocksToMarkdown on the first item, my numbered_list_item custom transformer used to be called for both items and both items would end up in the output.

Now, the child never makes it to the output at all.

This is true of any child with a custom transformer.

Was this an oversight? Or did you intend that if a custom transformer was used that the transformer should be responsible for handling the type and all its children? If the latter, could you provide an example of how this can most easily be accomplished?

souvikinator commented 1 year ago

Hi Andrew. I tried replicating the issue.

Considering bulleted_list_items

  1. One i sub one

and following a custom transformer.

n2m.setCustomTransformer("numbered_list_item", async (block) => {
  // deal with the block and it's children as per your need
  console.log(block);
});

Custom transformer deals with that specific block type and one has to deal with the children of that block.

When the custom transformer doesn't return anything (like in the above snippet), it should parse the numbered_list_items normally. However, on replicating the issue it doesn't work as intended.

Before proceeding I would like to confirm if this is the problem you are facing.

I understand the change was made to prevent some duplicate markdown from being created (https://github.com/souvikinator/notion-to-md/issues/62), but I think a different solution is needed.

Definitely, this is the issue and I am trying to come up with a alternative solution/

kmlbgn commented 8 months ago

Clearly it is a huge tradeoff being made here as there is a higher need for child handling than synced block handling I believe.