tiptap/docs/src/docPages/api/commands/insert-content.md

56 lines
933 B
Markdown
Raw Normal View History

# insertContent
The `insertContent` command adds the passed value to the document.
2021-04-08 04:53:31 +08:00
See also: [setContent](/api/commands/set-content), [clearContent](/api/commands/clear-content)
## Parameters
2021-04-08 04:53:31 +08:00
`value: Content`
The command is pretty flexible and takes plain text, HTML or even JSON as a value.
2021-04-08 04:53:31 +08:00
## Usage
```js
2021-04-08 04:53:31 +08:00
// Plain text
2021-04-08 06:13:51 +08:00
editor.commands.insertContent('Example Text')
2021-04-08 04:53:31 +08:00
// HTML
2021-04-08 06:13:51 +08:00
editor.commands.insertContent('<h1>Example Text</h1>')
2021-04-08 04:53:31 +08:00
// JSON/Nodes
2021-04-08 06:13:51 +08:00
editor.commands.insertContent({
type: 'heading',
attrs: {
2021-04-08 04:53:31 +08:00
level: 1,
},
content: [
{
type: 'text',
2021-04-08 04:53:31 +08:00
text: 'Example Text',
},
],
})
2021-05-05 20:19:24 +08:00
// Multiple nodes at once
editor.commands.insertContent([
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'First paragraph',
},
],
},
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Second paragraph',
},
],
},
])
```