# autoformat/blockautoformatediting

module

<a id="functions">

## Functions

<a id="function-blockAutoformatEditing">

### `blockAutoformatEditing( editor, plugin, pattern, callbackOrCommand ) → void`

Creates a listener triggered on [`change:data`](module_engine_model_document-ModelDocument.md#event-change:data) event in the document. Calls the callback when inserted text matches the regular expression or the command name if provided instead of the callback.

Examples of usage:

To convert a paragraph into heading 1 when `- `is typed, using just the command name:

```typescript
blockAutoformatEditing( editor, plugin, /^\- $/, 'heading1' );
```

To convert a paragraph into heading 1 when `- `is typed, using just the callback:

```typescript
blockAutoformatEditing( editor, plugin, /^\- $/, ( context ) => {
	const { match } = context;
	const headingLevel = match[ 1 ].length;

	editor.execute( 'heading', {
		formatId: `heading${ headingLevel }`
	} );
} );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-autoformat/src/blockautoformatediting.ts#L73)

#### Parameters

* `editor: Editor`

  The editor instance.

* `plugin: Autoformat`

  The autoformat plugin instance.

* `pattern: RegExp`

  The regular expression to execute on just inserted text. The regular expression is tested against the text from the beginning until the caret position.

* `callbackOrCommand: string | ( context: object ) => unknown`

  The callback to execute or the command to run when the text is matched. In case of providing the callback, it receives the following parameter:

  * match RegExp.exec() result of matching the pattern to inserted text.

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
