notion-to-md icon indicating copy to clipboard operation
notion-to-md copied to clipboard

Toggle summary may be truncated

Open smor opened this issue 1 year ago • 4 comments

Hello,

I'm trying to convert a Notion /toggle's summary properly, but it is truncated.

This : image is converted as :

<summary>Les principes de base du fonctionnement des Fablabs ont été définis par la&nbsp;</summary>

This is due to https://github.com/souvikinator/notion-to-md/blob/master/src/notion-to-md.ts#L305 handling rich_text[0] only.

Directly producing HTML is not this package's purpose and I'd rather output the full summary as Markdown, but outputting <details> and <summary> is probably the only way this can be done.

Any idea on how to deal with this properly ?

smor avatar Jul 28 '22 09:07 smor

Correct me if I got your requirement wrong. You want to render the annotations as well in the toggle summary ?

souvikinator avatar Jul 29 '22 01:07 souvikinator

IMHO the toggle summary should be treated like any other paragraph and be rendered fully with annotations indeed, links, etc. The difficulty lies in keeping a functional Markdown output along with HTML tags required to produce the toggle, right ?

smor avatar Jul 29 '22 05:07 smor

True, maybe I should treat toggle as paragraph, but I'm sure it's going to break a lot of websites using this package. Any preferred format you have in mind?

I tried using setCustomTransformer like so:

n2m.setCustomTransformer("toggle", async (block) => {
  const { toggle } = block as any;
  // console.log(toggle);
  let toggle_text = "";
  toggle.rich_text.forEach((rich_text: any) => {
    toggle_text += n2m.annotatePlainText(
      rich_text.plain_text,
      rich_text.annotations
    );
  });
  return toggle_text;
});

output:

This is a <u>~~**toggle**~~</u>

however this won't deal with the toggle children.

souvikinator avatar Jul 30 '22 07:07 souvikinator

Directly producing HTML is not this package's purpose but outputting

and is probably the only way this can be done.

Remember HTML is also supported in markdown docs :)

GorvGoyl avatar Sep 22 '22 17:09 GorvGoyl