[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
- 更多模塊