Matcher (engine/view)
@ckeditor/ckeditor5-engine/src/view/matcher
View matcher class. Instance of this class can be used to find elements that match given pattern.
Filtering
Properties
-
private readonly
_patterns : Array<MatcherFunctionPattern | MatcherObjectPattern>
module:engine/view/matcher~Matcher#_patterns
Methods
-
constructor( pattern )
module:engine/view/matcher~Matcher#constructor
Creates new instance of Matcher.
Parameters
pattern : Array<MatcherPattern>
Match patterns. See add method for more information.
-
add( pattern ) → void
module:engine/view/matcher~Matcher#add
Adds pattern or patterns to matcher instance.
// String. matcher.add( 'div' ); // Regular expression. matcher.add( /^\w/ ); // Single class. matcher.add( { classes: 'foobar' } );
See
MatcherPattern
for more examples.Multiple patterns can be added in one call:
matcher.add( 'div', { classes: 'foobar' } );
Parameters
pattern : Array<MatcherPattern>
Object describing pattern details. If string or regular expression is provided it will be used to match element's name. Pattern can be also provided in a form of a function - then this function will be called with each element as a parameter. Function's return value will be stored under
match
key of the object returned from match or matchAll methods.
Returns
void
-
getElementName() → null | string
module:engine/view/matcher~Matcher#getElementName
Returns the name of the element to match if there is exactly one pattern added to the matcher instance and it matches element name defined by
string
(notRegExp
). Otherwise, returnsnull
.Returns
null | string
Element name trying to match.
-
match( element ) → null | MatchResult
module:engine/view/matcher~Matcher#match
Matches elements for currently stored patterns. Returns match information about first found element, otherwise returns
null
.Example of returned object:
{ element: <instance of found element>, pattern: <pattern used to match found element>, match: { name: true, attributes: [ 'title', 'href' ], classes: [ 'foo' ], styles: [ 'color', 'position' ] } }
Parameters
element : Array<Element>
View element to match against stored patterns.
Returns
null | MatchResult
Related:
-
matchAll( element ) → null | Array<MatchResult>
module:engine/view/matcher~Matcher#matchAll
Matches elements for currently stored patterns. Returns array of match information with all found elements. If no element is found - returns
null
.Parameters
element : Array<Element>
View element to match against stored patterns.
Returns
null | Array<MatchResult>
Array with match information about found elements or
null
. For more information see match method description.
Related:
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.