Formatting

format

格式化用户当前选择的文本,返回一个改变后的Delta对象。如果用户选择的长度为0,即使是一个光标,格式将被设置为激活状态,因此,用户键入的下一个字符将具有当前的格式。操作来源可能为:‘user’、‘api’或者‘silent’。当编辑器被禁用时,来源‘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对象。请参阅格式化列表以获取可用的格式。要删除格式,参数请传false。用户的选择可能不会被保留。操作来源可能为:‘user’、‘api’或者‘silent’。当编辑器被禁用时,来源‘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帮助器。请参阅格式化列表以获取可用的格式。要删除格式,参数请传false。用户的选择可能不会被保留。操作来源可能为:‘user’、‘api’或者‘silent’。当编辑器被禁用时,来源‘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); // 加粗 'hello'
  3. quill.formatText(0, 5, { // 取消加粗 'hello' 并且设置颜色为blue
  4. 'bold': false,
  5. 'color': 'rgb(0, 0, 255)'
  6. });
  7. quill.formatText(5, 1, 'align', 'right'); // 'hello' 行右对齐

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,
  15. // align: 'right' }

removeFormat

删除给定范围内的所有格式和嵌入,返回一个改变后的Delta对象。如果当前行的任何部分包含在范围内,行格式将被删除。用户的选择可能不会被保留。操作来源可能为:‘user’、‘api’或者‘silent’。当编辑器被禁用时,来源‘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. // 编辑器内容现在应该是
  11. // [
  12. // { insert: 'Hel', { bold: true } },
  13. // { insert: 'lo\n\nWo' },
  14. // { insert: 'rld', { italic: true }},
  15. // { insert: '\n', { align: 'center' } }
  16. // ]