Parsoid
A bidirectional parser between wikitext and HTML5
|
A chunk of wikitext output. More...
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. | |
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()
.
Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::__construct | ( | array | $args | ) |
array{text:string,node:Node,prefix?:string,suffix?:string} | $args Options. |
Reimplemented in Wikimedia\Parsoid\Html2Wt\ConstrainedText\RegExpConstrainedText.
|
static |
Ensure that the argument o
, which is perhaps a string, is a instance of ConstrainedText
.
string | ConstrainedText | $o | |
Node | $node | The Node corresponding to o . |
Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::equals | ( | ConstrainedText | $ct | ) |
Simple equality.
This enforces type equality (ie subclasses are not equal).
ConstrainedText | $ct |
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.
State | $state | Context state |
Reimplemented in Wikimedia\Parsoid\Html2Wt\ConstrainedText\AutoURLLinkText, Wikimedia\Parsoid\Html2Wt\ConstrainedText\RegExpConstrainedText, and Wikimedia\Parsoid\Html2Wt\ConstrainedText\WikiLinkText.
|
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).
ConstrainedText[] | $line |
|
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.
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.
string | $text | |
Element | $node | |
DataParsoid | $dataParsoid | |
Env | $env | |
array | $opts |
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.
Wikimedia\Parsoid\Html2Wt\ConstrainedText\ConstrainedText::matches | ( | string | $re, |
Env | $env ) |
Useful shortcut: execute a regular expression on the raw wikitext.
string | $re | |
Env | $env |