Skip to content

Error converting Image Block to Markdown #361

Description

@wkocjan

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

  1. Initialize editor with blocksToMarkdown() call in onEditorContentChange:
const editor = useBlockNote({
onEditorContentChange: editor => {
editor.blocksToMarkdown(editor.topLevelBlocks).then(markdown => {
console.debug(markdown);
});
},
});
  1. Open editor in the browser & insert Image Block. Immediately onEditorContentChange event will fire, causing blocksToMarkdown 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions