Formatting

format

格式化文本在用户当前选择,返回表示更改的Delta。 如果用户的选择长度为0,即它是光标,则格式将被设置为活动,因此用户键入的下一个字符将具有该格式。来源可以是“user”“api”“silent”禁用编辑器时,“source”“user”的调用将被忽略。

Methods

  1. format(name: String, value: any, source: String = 'api'): Delta

Examples

  1. quill.format('color', 'red');
  2. quill.format('align', 'right');

formatLine

格式化给定范围内的所有行,返回表示更改的Delta。请参阅可用格式列表的格式。 使用内联格式调用时无效。 要删除格式,请为value参数传递false。 用户的选择可能不会被保留。来源可以是“user”“api”“silent”禁用编辑器时,“source”“user”的调用将被忽略。

Methods

  1. formatLine(index: Number, length: Number, source: String = 'api'): Delta
  2. formatLine(index: Number, length: Number, format: String, value: any,
  3. source: String = 'api'): Delta
  4. formatLine(index: Number, length: Number, formats: { [String]: any },
  5. source: String = 'api'): Delta

Examples

  1. quill.setText('Hello\nWorld!\n');
  2. quill.formatLine(1, 2, 'align', 'right'); // right aligns the first line
  3. quill.formatLine(4, 4, 'align', 'center'); // center aligns both lines

formatText

在编辑器中格式化文本,返回表示更改的Delta。对于行级格式(如文本对齐),请定位换行符或使用上面的formatLine帮助完成。请参阅可用格式列表的格式。要删除格式,请为value参数传递false。 用户的选择可能不会被保留。来源可以是“user”“api”“silent”禁用编辑器时,“source”“user”的调用将被忽略。

Methods

  1. formatText(index: Number, length: Number, source: String = 'api'): Delta
  2. formatText(index: Number, length: Number, format: String, value: any,
  3. source: String = 'api'): Delta
  4. formatText(index: Number, length: Number, formats: { [String]: any },
  5. source: String = 'api'): Delta

Examples

  1. quill.setText('Hello\nWorld!\n');
  2. quill.formatText(0, 5, 'bold', true); // bolds 'hello'
  3. quill.formatText(0, 5, { // unbolds 'hello' and set its color to blue
  4. 'bold': false,
  5. 'color': 'rgb(0, 0, 255)'
  6. });
  7. quill.formatText(5, 1, 'align', 'right'); // right aligns the 'hello' line

getFormat

检索给定范围内文本的常见格式。 对于要报告的格式,范围内的所有文本都必须具有真值。 如果存在不同的真值,则将报告具有所有真值的数组。 如果未提供范围,则使用用户的当前选择范围。 可用于显示光标上已设置的格式。 如果不带参数调用,则将使用用户的当前选择范围。

Methods

  1. getFormat(range: Range = current): { [String]: any }
  2. getFormat(index: Number, length: Number = 0): { [String]: any }

Examples

  1. quill.setText('Hello World!');
  2. quill.formatText(0, 2, 'bold', true);
  3. quill.formatText(1, 2, 'italic', true);
  4. quill.getFormat(0, 2); // { bold: true }
  5. quill.getFormat(1, 1); // { bold: true, italic: true }
  6. quill.formatText(0, 2, 'color', 'red');
  7. quill.formatText(2, 1, 'color', 'blue');
  8. quill.getFormat(0, 3); // { color: ['red', 'blue'] }
  9. quill.setSelection(3);
  10. quill.getFormat(); // { italic: true, color: 'blue' }
  11. quill.format('strike', true);
  12. quill.getFormat(); // { italic: true, color: 'blue', strike: true }
  13. quill.formatLine(0, 1, 'align', 'right');
  14. quill.getFormat(); // { italic: true, color: 'blue', strike: true, align: 'right' }

removeFormat

删除给定范围内的所有格式和嵌入,返回表示更改的Delta。如果行的任何部分包含在范围内,则将删除行格式。 用户的选择可能不会被保留。来源可以是“user”“api”“silent”禁用编辑器时,“source”“user”的调用将被忽略。

Methods

  1. removeFormat(index: Number, length: Number, source: String = 'api'): Delta

Examples

  1. quill.setContents([
  2. { insert: 'Hello', { bold: true } },
  3. { insert: '\n', { align: 'center' } },
  4. { insert: { formula: 'x^2' } },
  5. { insert: '\n', { align: 'center' } },
  6. { insert: 'World', { italic: true }},
  7. { insert: '\n', { align: 'center' } }
  8. ]);
  9. quill.removeFormat(3, 7);
  10. // Editor contents are now
  11. // [
  12. // { insert: 'Hel', { bold: true } },
  13. // { insert: 'lo\n\nWo' },
  14. // { insert: 'rld', { italic: true }},
  15. // { insert: '\n', { align: 'center' } }
  16. // ]