Skip to content

Commit 7a8ab18

Browse files
authored
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.
1 parent a61baa9 commit 7a8ab18

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/walkthroughs/04-applying-custom-formatting.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const App = () => {
3939
Transforms.setNodes(
4040
editor,
4141
{ type: match ? 'paragraph' : 'code' },
42-
{ match: n => Editor.isBlock(editor, n) }
42+
{ match: n => Element.isElement(n) && Editor.isBlock(editor, n) }
4343
)
4444
}
4545
}}
@@ -90,7 +90,7 @@ const App = () => {
9090
Transforms.setNodes(
9191
editor,
9292
{ type: match ? 'paragraph' : 'code' },
93-
{ match: n => Editor.isBlock(editor, n) }
93+
{ match: n => Element.isElement(n) && Editor.isBlock(editor, n) }
9494
)
9595
break
9696
}
@@ -178,7 +178,7 @@ const App = () => {
178178
Transforms.setNodes(
179179
editor,
180180
{ type: match ? null : 'code' },
181-
{ match: n => Editor.isBlock(editor, n) }
181+
{ match: n => Element.isElement(n) && Editor.isBlock(editor, n) }
182182
)
183183
break
184184
}

0 commit comments

Comments
 (0)