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