[TOC]
## format
<!--
Format text at user's current selection, returning a [Delta](../guides/designing-the-delta-format.md) representing the change. If the user's selection length is 0, i.e. it is a cursor, the format will be set active, so the next character the user types will have that formatting. [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)數據。如果用戶當前選擇的長度為0,只是一個游標,這個格式將被激活,所以用戶輸入的下一個字符將被應用這個格式。 [Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。當編輯器不可用[disabled]#disable且`source`參數為“user”時,調用將被忽略。
**方法**
```javascript
format(name: String, value: any, source: String = 'api'): Delta
```
**示例**
```javascript
quill.format('color', 'red');
quill.format('align', 'right');
```
## formatLine
<!--
Formats all lines in given range, returning a [Delta](../guides/designing-the-delta-format.md) representing the change. See [formats](/docs/formats/) for a list of available formats. Has no effect when called with inline formats. To remove formatting, pass `false` for the value argument. The user's selection may not be preserved. [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)數據。參見[formats](../格式formats.md)查看可用的格式列表。
傳入行內格式調用將沒有效果。傳入的參數value為`false`則會移除格式。用戶的選擇狀態將不會被保存。[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。當編輯器不可用[disabled]#disable且`source`參數為“user”時,調用將被忽略。
**方法**
```javascript
formatLine(index: Number, length: Number, source: String = 'api'): Delta
formatLine(index: Number, length: Number, format: String, value: any,
source: String = 'api'): Delta
formatLine(index: Number, length: Number, formats: { [String]: any },
source: String = 'api'): Delta
```
**示例**
```javascript
quill.setText('Hello\nWorld!\n');
quill.formatLine(1, 2, 'align', 'right'); // right aligns the first line
quill.formatLine(4, 4, 'align', 'center'); // center aligns both lines
```
## formatText
<!--
Formats text in the editor, returning a [Delta](../guides/designing-the-delta-format.md) representing the change. For line level formats, such as text alignment, target the newline character or use the [`formatLine`](#formatline) helper. See [formats](/docs/formats/) for a list of available formats. To remove formatting, pass `false` for the value argument. The user's selection may not be preserved. [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)數據。對行級別的格式如文本對齊,對準換行符或使用[`formatLine`](#formatline)方法。參見[formats](../格式formats.md)查看可用的格式列表。傳入的參數value為`false`則會移除格式。用戶的選擇狀態將不會被保存。[Source](事件events.md)可能是 `"user"`、 `"api"` 或者 `"silent"`。當編輯器不可用[disabled]#disable且`source`參數為“user”時,調用將被忽略。
**方法**
```javascript
formatText(index: Number, length: Number, source: String = 'api'): Delta
formatText(index: Number, length: Number, format: String, value: any,
source: String = 'api'): Delta
formatText(index: Number, length: Number, formats: { [String]: any },
source: String = 'api'): Delta
```
**示例**
```javascript
quill.setText('Hello\nWorld!\n');
quill.formatText(0, 5, 'bold', true); // bolds 'hello'
quill.formatText(0, 5, { // unbolds 'hello' and set its color to blue
'bold': false,
'color': 'rgb(0, 0, 255)'
});
quill.formatText(5, 1, 'align', 'right'); // right aligns the 'hello' line
```
## getFormat
<!--
Retrieves common formatting of the text in the given range. For a format to be reported, all text within the range must have a truthy value. If there are different truthy values, an array with all truthy values will be reported. If no range is supplied, the user's current selection range is used. May be used to show which formats have been set on the cursor. If called with no arguments, the user's current selection range will be used.
-->
返回傳入范圍內文本的一般格式。要輸出格式,在選區范圍內的所有文本必須有一個真值。如果有不同的真值,所有真值將作為一個數組輸出。如果沒有傳入范圍,將使用用戶的當前選區。也可以用于輸出當前光標位置的格式。如果沒有帶參數調用,將使用用戶的當前選擇區域。
**方法**
```javascript
getFormat(range: Range = current): { [String]: any }
getFormat(index: Number, length: Number = 0): { [String]: any }
```
**示例**
```javascript
quill.setText('Hello World!');
quill.formatText(0, 2, 'bold', true);
quill.formatText(1, 2, 'italic', true);
quill.getFormat(0, 2); // { bold: true }
quill.getFormat(1, 1); // { bold: true, italic: true }
quill.formatText(0, 2, 'color', 'red');
quill.formatText(2, 1, 'color', 'blue');
quill.getFormat(0, 3); // { color: ['red', 'blue'] }
quill.setSelection(3);
quill.getFormat(); // { italic: true, color: 'blue' }
quill.format('strike', true);
quill.getFormat(); // { italic: true, color: 'blue', strike: true }
quill.formatLine(0, 1, 'align', 'right');
quill.getFormat(); // { italic: true, color: 'blue', strike: true,
// align: 'right' }
```
## removeFormat
<!--
Removes all formatting and embeds within given range, returning a [Delta](../guides/designing-the-delta-format.md) representing the change. Line formatting will be removed if any part of the line is included in the range. The user's selection may not be preserved. [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
removeFormat(index: Number, length: Number, source: String = 'api'): Delta
```
**示例**
```javascript
quill.setContents([
{ insert: 'Hello', { bold: true } },
{ insert: '\n', { align: 'center' } },
{ insert: { formula: 'x^2' } },
{ insert: '\n', { align: 'center' } },
{ insert: 'World', { italic: true }},
{ insert: '\n', { align: 'center' } }
]);
quill.removeFormat(3, 7);
// Editor contents are now
// [
// { insert: 'Hel', { bold: true } },
// { insert: 'lo\n\nWo' },
// { insert: 'rld', { italic: true }},
// { insert: '\n', { align: 'center' } }
// ]
```
- 前言
- 快速開始(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
- 更多模塊