tiptap/docs/api/commands/set-content.md
2021-09-16 14:41:25 +02:00

1.1 KiB
Raw Blame History

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.

See also: insertContent, clearContent

Parameters

content: string

Pass a string (JSON or HTML) as content. The editor will only render whats allowed according to the schema.

emitUpdate?: Boolean (false)

By default, it doesnt trigger the update event. Passing true doesnt prevent triggering the update event.

parseOptions?: Record<string, any>

Options to configure the parsing can be passed during initialization and/or with setContent. Read more about parseOptions in the ProseMirror documentation.

Usage

// HTML
editor.commands.setContent('<p>Example Text</p>')

// JSON
editor.commands.setContent({
  "type": "doc",
  "content": [
    {
      "type": "paragraph",
      "content": [
        {
          "type": "text",
          "text": "Example Text"
        }
      ]
    }
  ]
})