Report an issue
Class

SchemaContext (engine/model)

@ckeditor/ckeditor5-engine/src/model/schema

class

A schema context – a list of ancestors of a given position in the document.

Considering such a position:

<$root>
    <blockQuote>
        <paragraph>
            ^
        </paragraph>
    </blockQuote>
</$root>

The context of this position is its lists of ancestors:

[ rootElement, blockQuoteElement, paragraphElement ]

Contexts are used in the Schema#checkChild and Schema#checkAttribute events as a definition of a place in the document where the check occurs. The context instances are created based on the first arguments of the Schema#checkChild() and Schema#checkAttribute() methods so when using these methods you need to use SchemaContextDefinitions.

Filtering

Properties

Methods

  • constructor( context )

    Creates an instance of the context.

    Parameters

    context : SchemaContextDefinition
  • Iterable interface.

    Iterates over all context items.

    Returns

    Iterable.<SchemaContextItem>
  • endsWith( query ) → Boolean

    Checks whether the context ends with the given nodes.

    const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] );
    
    ctx.endsWith( '$text' ); // -> true
    ctx.endsWith( 'paragraph $text' ); // -> true
    ctx.endsWith( '$root' ); // -> false
    ctx.endsWith( 'paragraph' ); // -> false

    Parameters

    query : String

    Returns

    Boolean
  • Gets an item on the given index.

  • getNames() → Iterable.<String>

    Returns the names of items.

    Returns

    Iterable.<String>
  • push( item ) → SchemaContext

    Returns new SchemaContext instance with additional item

    Item can be added as:

    const context = new SchemaContext( [ '$root' ] );
    
    // An element.
    const fooElement = writer.createElement( 'fooElement' );
    const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ]
    
    // A text node.
    const text = writer.createText( 'foobar' );
    const newContext = context.push( text ); // [ '$root', '$text' ]
    
    // A string (element name).
    const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]

    Note {module:engine/model/node~Node} that is already in the model tree will be added as the only item (without ancestors).

    Parameters

    item : String | Node | Array.<(String | Node)>

    Item that will be added to current context.

    Returns

    SchemaContext

    New SchemaContext instance with additional item.