From 7a8ab18c527c97aebcafe5b88032da38aa1664b0 Mon Sep 17 00:00:00 2001 From: aberllin <72520503+aberllin@users.noreply.github.com> Date: Mon, 10 Feb 2025 02:51:48 +0100 Subject: [PATCH] Fix: Ensure block transformation works in the example (#5803) I noticed that the current example for toggling a code block using the backtick (`) key doesn't work as expected. The issue occurs because `Editor.nodes()` can return text nodes instead of block elements, causing`Transforms.setNodes()` to fail. To fix this, I added an extra check using `Element.isElement(n)`, ensuring that only block elements are transformed. --- docs/walkthroughs/04-applying-custom-formatting.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/walkthroughs/04-applying-custom-formatting.md b/docs/walkthroughs/04-applying-custom-formatting.md index 5213891fe0..5fea3c7c2e 100644 --- a/docs/walkthroughs/04-applying-custom-formatting.md +++ b/docs/walkthroughs/04-applying-custom-formatting.md @@ -39,7 +39,7 @@ const App = () => { Transforms.setNodes( editor, { type: match ? 'paragraph' : 'code' }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) } }} @@ -90,7 +90,7 @@ const App = () => { Transforms.setNodes( editor, { type: match ? 'paragraph' : 'code' }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) break } @@ -178,7 +178,7 @@ const App = () => { Transforms.setNodes( editor, { type: match ? null : 'code' }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) break }