8
0
Просмотр исходного кода

Updated annotation to AutoformatEngine constructor.

Maksymilian Barnaś 9 лет назад
Родитель
Сommit
0daf58f16d
1 измененных файлов с 21 добавлено и 1 удалено
  1. 21 1
      packages/ckeditor5-autoformat/src/autoformatengine.js

+ 21 - 1
packages/ckeditor5-autoformat/src/autoformatengine.js

@@ -8,7 +8,27 @@ import TextProxy from '../engine/model/textproxy.js';
 
 export default class AutoformatEngine {
 	/**
-	 * Creates listener triggered on `change` event in document. Calls callback when inserted text matches regular expression.
+	 * Creates listener triggered on `change` event in document.
+	 * Calls callback when inserted text matches regular expression or command name
+	 * if provided instead of callback.
+	 *
+	 * Examples of usage:
+	 *
+	 * To convert paragraph to heading1 when `- ` is typed, using just commmand name:
+	 *
+	 *		createAutoformat( editor, /^\- $/, 'heading1');
+	 *
+	 * To convert paragraph to heading1 when `- ` is typed, using just callback:
+	 *
+	 *		createAutoformat( editor, /^\- $/, ( context ) => {
+	 *			const { batch, match } = context;
+	 *			const headingLevel = match[ 1 ].length;
+	 *
+	 *			editor.execute( 'heading', {
+	 *				batch,
+	 *				formatId: `heading${ headingLevel }`
+	 *			} );
+	 * 		} );
 	 *
 	 * @param {core.editor.Editor} editor Editor instance.
 	 * @param {Regex} pattern Regular expression to exec on just inserted text.