Skip to content

Commit

Permalink
Fix: Ensure block transformation works in the example (#5803)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aberllin authored Feb 10, 2025
1 parent a61baa9 commit 7a8ab18
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/walkthroughs/04-applying-custom-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
)
}
}}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7a8ab18

Please sign in to comment.