-
-
Notifications
You must be signed in to change notification settings - Fork 581
Closed
Labels
Description
Describe the bug
Newly inserted "Image Block" to the editor causes error when converting to markdown.
Error message:
Error: Expected node, not `undefined`
It happens when editor.blocksToMarkdown()
is called with empty Image Block.
To Reproduce
- Initialize editor with
blocksToMarkdown()
call inonEditorContentChange
:
const editor = useBlockNote({
onEditorContentChange: editor => {
editor.blocksToMarkdown(editor.topLevelBlocks).then(markdown => {
console.debug(markdown);
});
},
});
- Open editor in the browser & insert Image Block. Immediately
onEditorContentChange
event will fire, causingblocksToMarkdown
to run, which throws an error.
Here is the block object with empty image causing the error:
{
"id": "cdd6b0c5-fcb4-475c-a582-90a57f8639e1",
"type": "image",
"props": {
"backgroundColor": "default",
"textAlignment": "left",
"url": "",
"caption": "",
"width": 512
},
"content": undefined,
"children": []
}
Expected behavior
- Do not generate any markdown when image doesn't have url
- Generate markdown code (
[alt text](image_url)
) when there is an image.