Class: ConstrainedText

html2wt/ConstrainedText~ConstrainedText(args)

new ConstrainedText(args)

A chunk of wikitext output.

A chunk of wikitext output. This base class contains the wikitext and a pointer to the DOM node which is responsible for generating it. Subclasses can add additional properties to record context or wikitext boundary restrictions for proper escaping. The chunk is serialized with the escape method, which might alter the wikitext in order to ensure it doesn't run together with its context (usually by adding <nowiki> tags).

Parameters:
Name Type Description
args Object

Options.

Properties
Name Type Attributes Description
text string

The text string associated with this chunk.

node Node

The DOM Node associated with this chunk.

prefix string <optional>

The prefix string to add if the start of the chunk doesn't match its constraints.

suffix string <optional>

The suffix string to add if the end of the chunk doesn't match its constraints.

Source:

Methods

(static) cast(o, node) → {ConstrainedText}

Ensure that the argument o, which is perhaps a string, is a instance of ConstrainedText.

Ensure that the argument o, which is perhaps a string, is a instance of ConstrainedText.

Parameters:
Name Type Description
o string | ConstrainedText
node Node

The DOM Node corresponding to o.

Source:
Returns:
Type
ConstrainedText

(static) fromSelSer(text, node, dataParsoid, env, opts)

SelSer support: when we come across an unmodified node in during selective serialization, we know we can use the original wikitext for that node unmodified.

SelSer support: when we come across an unmodified node in during selective serialization, we know we can use the original wikitext for that node unmodified. But there may be boundary conditions on the left and right sides of the selser'ed text which are going to require escaping.

So rather than turning the node into a plain old ConstrainedText chunk, allow subclasses of ConstrainedText to register as potential handlers of selser nodes. A selser'ed magic link, for example, will then turn into a MagicLinkText and thus be able to enforce the proper boundary constraints.

Parameters:
Name Type Description
text string
node Node
dataParsoid Object
env MWParserEnvironment
opts Object
Source:

(static) register(subtype)

Add a subtype to the list of types we attempt fromSelSer with.

Add a subtype to the list of types we attempt fromSelSer with.

Parameters:
Name Type Description
subtype ConstrainedText

A subclass of ConstrainedText.

Source:

equals(ct) → {boolean}

Simple equality.

Simple equality. This enforces type equality (ie subclasses are not equal).

Parameters:
Name Type Description
ct Object
Source:
Returns:
Type
boolean

escape(state) → {Object|string|string|string}

Use the provided state, which gives context and access to the entire list of chunks, to determine the proper escape prefix/suffix.

Use the provided state, which gives context and access to the entire list of chunks, to determine the proper escape prefix/suffix. Returns an object with a text property as well as optional prefix and 'suffix' properties giving desired escape strings.

Parameters:
Name Type Description
state Object
Source:
Returns:

match(re) → {Array|null}

Useful shortcut: execute a regular expression on the raw wikitext.

Useful shortcut: execute a regular expression on the raw wikitext.

Parameters:
Name Type Description
re RegExp
Source:
Returns:

An Array containing the matched results or null if there were no matches.

Type
Array | null