Class

BlockAutoformatEditing (autoformat)

@ckeditor/ckeditor5-autoformat/src/blockautoformatediting

class

The block autoformatting engine. It allows to format various block patterns. For example, it can be configured to turn a paragraph starting with * and followed by a space into a list item.

The autoformatting operation is integrated with the undo manager, so the autoformatting step can be undone if the user's intention was not to format the text.

See the constructors documentation to learn how to create custom inline autoformatters. You can also use the Autoformat feature which enables a set of default autoformatters (lists, headings, bold and italic).

Filtering

Properties

Static properties

  • pluginName

    static

Methods

  • constructor( editor, pattern, callbackOrCommand )

    Creates a listener triggered on change 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 to heading 1 when - is typed, using just the command name:

    new BlockAutoformatEditing( editor, /^\- $/, 'heading1' );

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

    new BlockAutoformatEditing( editor, /^\- $/, ( context ) => {
        const { match } = context;
        const headingLevel = match[ 1 ].length;
    
        editor.execute( 'heading', {
            formatId: `heading${ headingLevel }`
        } );
    } );

    Parameters

    editor : Editor

    The editor instance.

    pattern : RegExp

    The regular expression to execute on just inserted text.

    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.