Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText Class Reference

A chunk of wikitext output. More...

+ Inheritance diagram for Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText:

Public Member Functions

 __construct (array $args)
 
 escape (State $state)
 Use the provided state, which gives context and access to the entire list of chunks, to determine the proper escape prefix/suffix.
 
 equals (ConstrainedText $ct)
 Simple equality.
 
 matches (string $re, Env $env)
 Useful shortcut: execute a regular expression on the raw wikitext.
 

Static Public Member Functions

static escapeLine (array $line)
 This adds necessary escapes to a line of chunks.
 
static cast ( $o, Node $node)
 Ensure that the argument o, which is perhaps a string, is a instance of ConstrainedText.
 
static fromSelSer (string $text, Element $node, DataParsoid $dataParsoid, Env $env, array $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.
 

Public Attributes

 $text
 
 $node
 
 $prefix
 
 $suffix
 
 $selser
 
 $noSep
 

Static Protected Member Functions

static fromSelSerImpl (string $text, Element $node, DataParsoid $dataParsoid, Env $env, array $opts)
 Base case: the given node type does not correspond to a special ConstrainedText subclass.
 

Detailed Description

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 & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::__construct ( array $args)
Parameters
array{text:string,node:Node,prefix?:string,suffix?:string}$args Options.

Reimplemented in Wikimedia\Parsoid\Html2Wt\ConstrainedText\RegExpConstrainedText.

Member Function Documentation

◆ cast()

static Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::cast ( $o,
Node $node )
static

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

Parameters
string | ConstrainedText$o
Node$nodeThe Node corresponding to o.
Returns
ConstrainedText

◆ equals()

Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::equals ( ConstrainedText $ct)

Simple equality.

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

Parameters
ConstrainedText$ct
Returns
bool

◆ escape()

Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::escape ( State $state)

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
State$stateContext state
Returns
Result

Reimplemented in Wikimedia\Parsoid\Html2Wt\ConstrainedText\AutoURLLinkText, Wikimedia\Parsoid\Html2Wt\ConstrainedText\RegExpConstrainedText, and Wikimedia\Parsoid\Html2Wt\ConstrainedText\WikiLinkText.

◆ escapeLine()

static Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::escapeLine ( array $line)
static

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
ConstrainedText[]$line
Returns
string

◆ fromSelSer()

static Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::fromSelSer ( string $text,
Element $node,
DataParsoid $dataParsoid,
Env $env,
array $opts = [] )
static

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
string$text
Element$node
DataParsoid$dataParsoid
Env$env
array$opts
Returns
ConstrainedText[]

◆ fromSelSerImpl()

static Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::fromSelSerImpl ( string $text,
Element $node,
DataParsoid $dataParsoid,
Env $env,
array $opts )
staticprotected

Base case: the given node type does not correspond to a special ConstrainedText subclass.

We still have to be careful: the leftmost (rightmost) children of node may still be exposed to our left (right) context. If so (ie, their DSR bounds coincide) split the selser text and emit multiple ConstrainedText chunks to preserve the proper boundary conditions.

Parameters
string$text
Element$node
DataParsoid$dataParsoid
Env$env
array$opts
Returns
ConstrainedText|ConstrainedText[]

Reimplemented in Wikimedia\Parsoid\Html2Wt\ConstrainedText\AutoURLLinkText, Wikimedia\Parsoid\Html2Wt\ConstrainedText\ExtLinkText, Wikimedia\Parsoid\Html2Wt\ConstrainedText\LanguageVariantText, Wikimedia\Parsoid\Html2Wt\ConstrainedText\MagicLinkText, and Wikimedia\Parsoid\Html2Wt\ConstrainedText\WikiLinkText.

◆ matches()

Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::matches ( string $re,
Env $env )

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

Parameters
string$re
Env$env
Returns
array|null An array containing the matched results or null if there were no matches.

The documentation for this class was generated from the following file: