mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-28 07:40:13 +08:00
docs: update content
This commit is contained in:
parent
e61b2a51ed
commit
fa23bae5b5
@ -1,12 +1,23 @@
|
||||
# clearContent
|
||||
The `clearContent` command deletes the current document.
|
||||
|
||||
See also: [setContent](/api/commands/set-content)
|
||||
Keep in mind that the editor will enforce the configured schema, and the document won’t be `null`. The default [`Document`](/api/nodes/document) expects to have at least one block node, which is the paragraph by default. In other words: Even after running that command the document will have at least one (empty) paragraph.
|
||||
|
||||
See also: [setContent](/api/commands/set-content), [insertContent](/api/commands/insert-content)
|
||||
|
||||
## Parameters
|
||||
|
||||
`emitUpdate: Boolean (false)`
|
||||
|
||||
By default, it doesn’t trigger the update event. Passing `true` doesn’t prevent triggering the update event.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
// Remoe all content from the document
|
||||
this.editor.commands.clearContent()
|
||||
|
||||
// Remove all content, and trigger the `update` event
|
||||
this.editor.commands.clearContent(true)
|
||||
```
|
||||
|
||||
|
@ -1,21 +1,32 @@
|
||||
# insertContent
|
||||
The `insertContent` command adds a passed value to the document.
|
||||
|
||||
See also: [setContent](/api/commands/set-content), [clearContent](/api/commands/clear-content)
|
||||
|
||||
## Parameters
|
||||
|
||||
## Usage
|
||||
`value: Content`
|
||||
|
||||
The command is pretty flexible and takes plain text, HTML or even JSON as a value.
|
||||
|
||||
## Usage
|
||||
```js
|
||||
this.editor.commands.insertContent('text')
|
||||
this.editor.commands.insertContent('<p>HTML</p>')
|
||||
// Plain text
|
||||
this.editor.commands.insertContent('Example Text')
|
||||
|
||||
// HTML
|
||||
this.editor.commands.insertContent('<h1>Example Text</h1>')
|
||||
|
||||
// JSON/Nodes
|
||||
this.editor.commands.insertContent({
|
||||
type: 'heading',
|
||||
attrs: {
|
||||
level: 2,
|
||||
level: 1,
|
||||
},
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'nested nodes',
|
||||
text: 'Example Text',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
# setContent
|
||||
The `setContent` command replaces the document with a new one. You can pass JSON or HTML, both work fine. It’s basically the same as setting the `content` on initialization.
|
||||
|
||||
See also: [clearContent](/api/commands/clear-content)
|
||||
See also: [insertContent](/api/commands/insert-content), [clearContent](/api/commands/clear-content)
|
||||
|
||||
## Parameters
|
||||
|
||||
@ -9,7 +9,7 @@ See also: [clearContent](/api/commands/clear-content)
|
||||
|
||||
Pass a string (JSON or HTML) as [content](/guide/output). The editor will only render what’s allowed according to the [schema](/api/schema).
|
||||
|
||||
`emitUpdate?: Boolean`
|
||||
`emitUpdate?: Boolean (false)`
|
||||
|
||||
By default, it doesn’t trigger the update event. Passing `true` doesn’t prevent triggering the update event.
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
**The `Document` extension is required**, no matter what you build with tiptap. It’s a so called “topNode”, a node that’s the home to all other nodes. Think of it like the `<body>` tag for your document.
|
||||
|
||||
The node is very tiny though. It defines a name of the node (`document`), is configured to be a top node (`topNode: true`) and that it can contain multiple other nodes (`block`). That’s all. But have a look yourself:
|
||||
The node is very tiny though. It defines a name of the node (`document`), is configured to be a top node (`topNode: true`) and that it can contain multiple other nodes (`block+`). That’s all. But have a look yourself:
|
||||
|
||||
:::warning Breaking Change from 1.x → 2.x
|
||||
tiptap 1 tried to hide that node from you, but it has always been there. You have to explicitly import it from now on (or use `defaultExtensions()`).
|
||||
|
@ -135,10 +135,8 @@
|
||||
items:
|
||||
- title: clearContent
|
||||
link: /api/commands/clear-content
|
||||
type: draft
|
||||
- title: insertContent
|
||||
link: /api/commands/insert-content
|
||||
type: draft
|
||||
- title: setContent
|
||||
link: /api/commands/set-content
|
||||
- title: Nodes
|
||||
|
Loading…
Reference in New Issue
Block a user