Expand all

mw.editcheck.TextMatchRule

Constructor

new mw.editcheck.TextMatchRule(rule, id, collator) #

TextMatchRule

Class to represent a single matchRule for TextMatchEditCheck

Parameters:

Name Type Description
rule Object

Match rule

Properties:
Name Type Attributes Description
title string

Title of the match rule, used in the action prompt

message string

Message to show in the action description

query Object.<string, string> | Array.<string> | string

Terms to match, string, array or object mapping terms to their replacements.

mode string optional

'info', 'replace', or 'delete', to determine the type of action to show for this matchRule.

config Object optional

Configuration options.

expand string optional

Expansions mode 'sentence', 'paragraph', 'word', 'siblings', or 'parent'

inNode string optional

Node type that a match must be inside of

listener string optional

Listener that this matchRule applies to, if not all

preserveCase boolean optional

If the replacement should match the case of the found term

isRegExp boolean optional

If the query should be treated as a regular expression

caseSensitive boolean optional

If search should be case sensitive

minOccurrences boolean optional

Number of query instances that need to be found before it's declared a match

id string

ID of matchRule in config

collator Intl.Collator

Collator to use for comparisons

Source:

TextMatchRule

Class to represent a single matchRule for TextMatchEditCheck

Methods

getExpandedFragment(fragment) → {ve.dm.SurfaceFragment} #

Expand a fragment given the match rule's config

Parameters:

Name Type Description
fragment ve.dm.SurfaceFragment

Returns:

Expanded fragment

Type
ve.dm.SurfaceFragment
Source:
Expand a fragment given the match rule's config

getReplacement(term) → {string} #

Return the corresponding replacement word, as defined for the given word in this matchRule's query

Parameters:

Name Type Description
term string

to get replacement for

Returns:

replacement term

Type
string
Source:

Return the corresponding replacement word, as defined for the given word in this matchRule's query

getSubTag(term) → {string} #

Get a unique subtag for this matchRule-term pair. Builds the subtag from:

  • the index of the matchRule when created
  • and, optionally, the index of the term in the list of keys from the matchRule's query

Parameters:

Name Type Description
term string

Returns:

A subtag in the format '-{matchIndex}-{termIndex}'

Type
string
Source:
Get a unique subtag for this matchRule-term pair.

isCaseSensitive() → {boolean} #

Returns:

if this matchRule is configured to be case sensitive

Type
boolean
Source:

isRangeInNode(range, surfaceModel) → {boolean} #

Check if a range is inside the required inNode type.

Parameters:

Name Type Description
range ve.Range
surfaceModel ve.dm.Surface

Returns:

Type
boolean
Source:
Check if a range is inside the required inNode type.

normalizeQuery(query) → {Object.<string, string>} #

Transform any query type into a dictionary of terms and their replacements, with a null replacement if none exists

Parameters:

Name Type Description
query Object.<string, string> | Array.<string> | string

Returns:

Dictionary of each term and its replacement

Type
Object.<string, string>
Source:

Transform any query type into a dictionary of terms and their replacements, with a null replacement if none exists