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
Great project! I really like the UI and the direction you're going.
I played a bit around in a NextJS project and found a couple of quirky issues that might have gone unnoticed. I'll report them in separate issues but here is the first one.
I followed the documentation on converting blocks to Markdown with this code snippet:
// Stores the editor's contents as Markdown.
const [markdown, setMarkdown] = useState<string>("");
// Creates a new editor instance.
const editor: BlockNoteEditor | null = useBlockNote({
// Listens for when the editor's contents change.
onEditorContentChange: (editor: BlockNoteEditor) => {
// Converts the editor's contents from Block objects to Markdown and
// saves them.
const saveBlocksAsMarkdown = async () => {
const markdown: string =
await editor.blocksToMarkdown(editor.topLevelBlocks);
setMarkdown(markdown);
};
saveBlocksAsMarkdown();
}
});
At first everything seemed to work as intended, but when copying a couple of websites to the editor (which converted the HTML to blocks in the background (excellent!)) in some cases I got the above error message.
Indeed, when investigating the block structure after pasting, I found this content block:
I am not sure what the HTML structure looked like that caused this. However, this doesn't seem to be intended.
I could solve the issue with manually checking for empty content nodes like this:
const removeEmptyTextBlocks = (blocks: Block[]) => {
// Visit all nodes
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i];
// Recursively remove empty text nodes from children
if (block.children) {
removeEmptyTextBlocks(block.children);
}
// Remove empty text nodes from content
if (block.content) {
const filteredContent = block.content.filter(
(contentNode) =>
!(contentNode.type === 'text' && contentNode.text === '')
);
block.content = filteredContent.length ? filteredContent : [];
}
}
};
// Listens for when the editor's contents change.
onEditorContentChange: (editor: BlockNoteEditor) => {
// Converts the editor's contents from Block objects to Markdown and
// saves them.
const saveBlocksAsMarkdown = async () => {
const blocks = editor.topLevelBlocks;
removeEmptyTextBlocks(blocks);
const markdown: string = await editor.blocksToMarkdown(blocks);
setValue(markdown);
};
saveBlocksAsMarkdown();
}
Probably though this problem should be fixed either in the editor.blocksToMarkdown function or whatever function is responsible for pasting HTML. Or even a check when creating new content blocks. I am not too familiar with your code base, so I am not creating a pull request myself.
Keep up the great work!
The text was updated successfully, but these errors were encountered:
Hi there!
Great project! I really like the UI and the direction you're going.
I played a bit around in a NextJS project and found a couple of quirky issues that might have gone unnoticed. I'll report them in separate issues but here is the first one.
I followed the documentation on converting blocks to Markdown with this code snippet:
At first everything seemed to work as intended, but when copying a couple of websites to the editor (which converted the HTML to blocks in the background (excellent!)) in some cases I got the above error message.
Indeed, when investigating the block structure after pasting, I found this content block:
I am not sure what the HTML structure looked like that caused this. However, this doesn't seem to be intended.
I could solve the issue with manually checking for empty content nodes like this:
Probably though this problem should be fixed either in the
editor.blocksToMarkdown
function or whatever function is responsible for pasting HTML. Or even a check when creating new content blocks. I am not too familiar with your code base, so I am not creating a pull request myself.Keep up the great work!
The text was updated successfully, but these errors were encountered: