tiptap/docs/api/commands/toggle-node.md

25 lines
617 B
Markdown
Raw Normal View History

2021-04-21 17:03:33 +08:00
# toggleNode
2023-05-12 01:56:36 +08:00
`toggleNode` will toggle a node with another node.
2021-04-21 17:03:33 +08:00
## Parameters
`typeOrName: string | NodeType`
The type of node that should be toggled.
`toggleTypeOrName: string | NodeType`
The type of node that should be used for the toggling.
`attributes?: Record<string, any>`
The attributes that should be applied to the node. **This is optional.**
## Usage
```js
// toggle a paragraph with a heading node
editor.commands.toggleNode('paragraph', 'heading', { level: 1 })
// toggle a paragraph with a image node
editor.commands.toggleNode('paragraph', 'image', { src: 'https://example.com/image.png' })
```