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

41 lines
1.1 KiB
Markdown
Raw Normal View History

2021-04-07 05:36:07 +08:00
# setContent
The `setContent` command replaces the document with a new one. You can pass JSON or HTML, both work fine. Its basically the same as setting the `content` on initialization.
2021-04-08 04:53:31 +08:00
See also: [insertContent](/api/commands/insert-content), [clearContent](/api/commands/clear-content)
2021-04-07 05:36:07 +08:00
## Parameters
`content: string`
Pass a string (JSON or HTML) as [content](/guide/output). The editor will only render whats allowed according to the [schema](/api/schema).
2021-04-08 04:53:31 +08:00
`emitUpdate?: Boolean (false)`
2021-04-07 05:36:07 +08:00
By default, it doesnt trigger the update event. Passing `true` doesnt prevent triggering the update event.
`parseOptions?: AnyObject`
Options to configure the parsing can be passed during initialization and/or with setContent. Read more about parseOptions in the [ProseMirror documentation](https://prosemirror.net/docs/ref/#model.ParseOptions).
## Usage
```js
// HTML
2021-04-08 06:13:51 +08:00
editor.commands.setContent('<p>Example Text</p>')
// JSON
2021-04-08 06:13:51 +08:00
editor.commands.setContent({
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Example Text"
}
]
}
]
})
2021-04-07 05:36:07 +08:00
```