You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
It would be really useful to be able to add markup before and after children blocks. It would allow us to inject html tags more easily. The "outline structure" of Notion blocks could be used to specify children of a tag in a natural way. Since most (all?) markdown parsers accept html, it makes sense to me to easily allow replacing blocks with html tags.
One obvious candidate for such feature is the toggle block. I saw that you currently need to re-fetch children blocks inside the toggle transform function. Wouldn't it be more consistent if the parent toggle block only outputs <details><summary>${summary}</summary> as 'opening output' and </details> as 'closing output'? Then the children's outputs would be injected in between the opening and closing strings of the parent.
Of course, there would be some considerations to keep in mind. For example, children would need to be aware of all their parents' types because we shouldn't mistakenly create <p> elements inside <p> elements for example.
That is not really up to this library to make this check but simply allow one to implement her own logic with the setCustomTransformer function.
Example
n2m.setCustomTransformer("toggle",async(block,ancestors)=>{const{ has_children, toggle }=block;lettoggle_rich_md="";lettoggle_plain_text="";toggle.rich_text.forEach((rich_text)=>{toggle_rich_md+=n2m.annotatePlainText(rich_text.plain_text,rich_text.annotations);toggle_plain_text+=rich_text.plain_text});// if a string is returned, it is the 'opening output' and there is no 'closing output'// (so it stays consistent with the current API)if(!has_children)return`<p>${toggle_rich_md}</p>`// if an object is returned, children of this block will be written between the 'open' string and the 'close' stringreturn{open: `<details><summary>${toggle_plain_text}</summary>`,close: `</details>`};});
The text was updated successfully, but these errors were encountered:
PS: it would also make it super easy to integrate with tools like Markdoc or even MDX which need opening and closing tags and can add a ton of functionality.
Hi.
It would be really useful to be able to add markup before and after children blocks. It would allow us to inject html tags more easily. The "outline structure" of Notion blocks could be used to specify children of a tag in a natural way. Since most (all?) markdown parsers accept html, it makes sense to me to easily allow replacing blocks with html tags.
One obvious candidate for such feature is the toggle block. I saw that you currently need to re-fetch children blocks inside the toggle transform function. Wouldn't it be more consistent if the parent toggle block only outputs
<details><summary>${summary}</summary>
as 'opening output' and</details>
as 'closing output'? Then the children's outputs would be injected in between the opening and closing strings of the parent.Of course, there would be some considerations to keep in mind. For example, children would need to be aware of all their parents' types because we shouldn't mistakenly create
<p>
elements inside<p>
elements for example.That is not really up to this library to make this check but simply allow one to implement her own logic with the
setCustomTransformer
function.Example
The text was updated successfully, but these errors were encountered: