Class: ConstrainedText

html2wt/ConstrainedText~ConstrainedText(args)

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).

The main entry point is the static function ConstrainedText.escapeLine().

Constructor

new ConstrainedText(args)

...
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:

Members

(static) _types

List of types we attempt fromSelSer with.

List of types we attempt fromSelSer with. This should include all the concrete subclasses of ConstrainedText (RegExpConstrainedText is missing since it is an abstract class). We also include the ConstrainedText class as the first element (even though it is an abstract base class) as a little bit of a hack: it simplifies ConstrainedText.fromSelSer by factoring some of its work into ConstrainedText._fromSelSer.

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) escapeLine(line) → {string}

This adds necessary escapes to a line of chunks.

This adds necessary escapes to a line of chunks. We provide the ConstrainedText#escape function with its left and right context, and it can determine what escapes are needed.

The line parameter is an array of ConstrainedText chunks which make up a line (or part of a line, in some cases of nested processing).

Parameters:
Name Type Description
line Array.<ConstrainedText>
Source:
Returns:
Type
string

(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:

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