[TOC]
## deleteText
<!--
Deletes text from the editor, returning a [Delta](../guides/designing-the-delta-format.md) representing the change. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
-->
从编辑器中删除文本,返回代表对应变化的[Delta](../guides/designing-the-delta-format.md)数据。[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。当编辑器不可用[disabled]#disable且`source`参数为“user”时,调用将被忽略。
**方法**
```javascript
deleteText(index:Number, length: Number, source: String = 'api'): Delta
```
**示例**
```javascript
quill.deleteText(6, 4);
```
## getContents
<!--
Retrieves contents of the editor, with formatting data, represented by a [Delta]() object.
-->
返回编辑器的内容——包含格式数据的[Delta](../增量Delta.md)数据。
**方法**
```javascript
getContents(index: Number = 0, length: Number = remaining): Delta
```
**示例**
```javascript
var delta = quill.getContents();
```
## getLength
<!--
Retrieves the length of the editor contents. Note even when Quill is empty, there is still a blank line represented by '\n', so `getLength` will return 1.
-->
返回编辑器内容的长度。注意,当Quill为空时,仍然包含一个由'\n'解析成的空行,所以`getLength`将返回1。
**方法**
```javascript
getLength(): Number
```
**示例**
```javascript
var length = quill.getLength();
```
## getText
<!--
Retrieves the string contents of the editor. Non-string content are omitted, so the returned string's length may be shorter than the editor's as returned by [`getLength`](#getlength). Note even when Quill is empty, there is still a blank line in the editor, so in these cases `getText` will return '\n'.
The `length` parameter defaults to the length of the remaining document.
-->
返回编辑器的字符串内容。由于非字符串内容会被忽略掉,所以返回字符串内容的长度会比[`getLength`](#getlength)返回的长度小。注意,尽管Quill为空,编辑器里仍有一行空行,所以这种情况会返回”\n”。
`length`参数默认为剩下文本的长度。
**方法**
```javascript
getText(index: Number = 0, length: Number = remaining): String
```
**示例**
```javascript
var text = quill.getText(0, 10);
```
## insertEmbed
<!--
Insert embedded content into the editor, returning a [Delta](../guides/designing-the-delta-format.md) representing the change. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
-->
插入嵌入对象内容到编辑器,返回代表对应变化的[Delta](../guides/designing-the-delta-format.md)数据。 [Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。当编辑器不可用[disabled]#disable且`source`参数为“user”时,调用将被忽略。
**方法**
```javascript
insertEmbed(index: Number, type: String, value: any, source: String = 'api'): Delta
```
**示例**
```javascript
quill.insertEmbed(10, 'image', 'https://quilljs.com/images/cloud.png');
```
## insertText
<!--
Inserts text into the editor, optionally with a specified format or multiple [formats](/docs/formats/). Returns a [Delta](../guides/designing-the-delta-format.md) representing the change. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
-->
向编辑器中插入文本,可选带有指定的文本格式或多个文本[格式](../格式formats.md),返回代表对应变化的[Delta](../guides/designing-the-delta-format.md)数据。
[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。当编辑器不可用[disabled]#disable且`source`参数为“user”时,调用将被忽略。
**方法**
```javascript
insertText(index: Number, text: String, source: String = 'api'): Delta
insertText(index: Number, text: String, format: String, value: any,
source: String = 'api'): Delta
insertText(index: Number, text: String, formats: { [String]: any },
source: String = 'api'): Delta
```
**示例**
```javascript
quill.insertText(0, 'Hello', 'bold', true);
quill.insertText(5, 'Quill', {
'color': '#ffff00',
'italic': true
});
```
## pasteHTML
***弃用的***
<!--
This API has been moved into [Clipboard](/docs/modules/clipboard/#dangerouslypastehtml) and renamed. It will be removed as a top level API in 2.0.
-->
这个接口已经移动到[Clipboard](../modules/粘贴板clipboard.md)中,并且重命名。在更高版本的2.0API中,它将被移除。
## setContents
<!--
Overwrites editor with given contents. Contents should end with a [newline](#line-formatting). Returns a Delta representing the change. This will be the same as the Delta passed in, if given Delta had no invalid operations. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
-->
用给定的内容覆盖原编辑器内容。内容将会用[换行符](../增量Delta.md)结尾。返回代表对应变化的Delta数据。如果给定的Delta没有无效的操作,返回值和传入的值相同。
[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。当编辑器不可用[disabled]#disable且`source`参数为“user”时,调用将被忽略。
**方法**
```javascript
setContents(delta: Delta, source: String = 'api'): Delta
```
**示例**
```javascript
quill.setContents([
{ insert: 'Hello ' },
{ insert: 'World!', attributes: { bold: true } },
{ insert: '\n' }
]);
```
## setText
<!--
Sets contents of editor with given text, returing a [Delta](../guides/designing-the-delta-format.md) representing the change. Note Quill documents must end with a newline so one will be added for you if omitted. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
-->
用给定的文本设置为编辑器的内容,返回代表对应变化的 [Delta](../guides/designing-the-delta-format.md)数据。注意,Quill文档必须以换行符结尾,如果没有则会自动添加。
[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。当编辑器不可用[disabled]#disable且`source`参数为“user”时,调用将被忽略。
**方法**
```javascript
setText(text: String, source: String = 'api'): Delta
```
**示例**
```javascript
quill.setText('Hello\n');
```
## updateContents
<!--
Applies Delta to editor contents, returing a [Delta](../guides/designing-the-delta-format.md) representing the change. These Deltas will be the same if the Delta passed in had no invalid operations. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
-->
让编辑器内容执行Delta数据方法,返回代表对应变化的 [Delta](../guides/designing-the-delta-format.md)数据。如果给定的Delta没有无效的操作,返回值和传入的值相同。
[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。当编辑器不可用[disabled]#disable且`source`参数为“user”时,调用将被忽略。
**方法**
```javascript
updateContents(delta: Delta, source: String = 'api'): Delta
```
**示例**
```javascript
// Assuming editor currently contains [{ insert: 'Hello World!' }]
quill.updateContents(new Delta()
.retain(6) // Keep 'Hello '
.delete(5) // 'World' is deleted
.insert('Quill')
.retain(1, { bold: true }) // Apply bold to exclamation mark
});
// Editor should now be [
// { insert: 'Hello Quill' },
// { insert: '!', attributes: { bold: true} }
// ]
```
- 前言
- 快速开始(quick_start)
- 下载(download)
- 配置(configuration)
- 格式(formats)
- API
- 内容(contents)
- 格式化(formatting)
- 选区(selection)
- 编辑器(editor)
- 事件(events)
- 模型(model)
- 扩展(extension)
- 增量(Delta)
- 模块(modules)
- 工具栏(toolbar)
- 键盘(keyboard)
- 历史记录(history)
- 粘贴板(clipboard)
- 语法高亮(syntax)
- 主题(themes)
- 更多教程
- 为什么选择Quill?
- 如何定制Quill?
- 设计Delta格式(未翻译)
- 构建一个自定义模块
- 将Quill加入你的编译管线(未翻译)
- Cloning Medium with Parchment
- 和其它富文本编辑器的对比(未翻译)
- Designing the Delta Format
- 扩展模块
- vue-quill-editor
- quill-image-extend-module
- quill-image-resize-module
- quill-image-drop-module
- quill-better-table
- quilljs-table
- 更多模块