Examples of usage:
To convert a paragraph to heading 1 when -
is typed, using just the command name:
blockAutoformatEditing( editor, plugin, /^\- $/, 'heading1' );
To convert a paragraph to heading 1 when -
is typed, using just the callback:
blockAutoformatEditing( editor, plugin, /^\- $/, ( context ) => {
const { match } = context;
const headingLevel = match[ 1 ].length;
editor.execute( 'heading', {
formatId: `heading${ headingLevel }`
} );
} );
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
:
function | String
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:
- {Object} match RegExp.exec() result of matching the pattern to inserted text.