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

Represents a preprocessor "piece". More...

+ Inheritance diagram for Wikimedia\Parsoid\Tokens\PreprocTk:
+ Collaboration diagram for Wikimedia\Parsoid\Tokens\PreprocTk:

Public Member Functions

 getContents ()
 
 getContentsKV ()
 
 setContents (array $contents, SourceRange $tsr)
 
 setContentsKV (KV $contents)
 
 __clone ()
 
 jsonSerialize ()
 
 __toString ()
 Return the string form of this PreprocTk; this should be identical to the original "preprocessed" wikitext.
 
 getBarredArgs ()
 Split this token by | and return target and named args.
 
 print ( $pretty=true)
 Pretty-print a PreprocTk token.
 
- Public Member Functions inherited from Wikimedia\Parsoid\Tokens\Token
 toJsonArray ()
 
 getType ()
 Returns a string key for this token.
 
 addAttribute (string $name, $value, ?KVSourceRange $srcOffsets=null)
 Generic set attribute method.
 
 addNormalizedAttribute (string $name, $value, $origValue)
 Generic set attribute method with support for change detection.
 
 getAttributeV (string $name)
 Generic attribute accessor.
 
 getAttributeKV (string $name)
 Generic attribute accessor.
 
 hasAttribute (string $name)
 Generic attribute accessor.
 
 setAttribute (string $name, $value)
 Set an unshadowed attribute.
 
 setShadowInfo (string $name, $value, $origValue)
 Store the original value of an attribute in a token's dataParsoid.
 
 setShadowInfoIfModified (string $name, $value, $origValue)
 Store the original value of an attribute in a token's dataParsoid.
 
 getAttributeShadowInfo (string $name)
 Attribute info accessor for the wikitext serializer.
 
 removeAttribute (string $name)
 Completely remove all attributes with this name.
 
 addSpaceSeparatedAttribute (string $name, string $value)
 Add a space-separated property value.
 
 getWTSource (Source ... $source)
 Get the wikitext source of a token.
 
 fetchExpandedAttrValue (string $key)
 

Static Public Member Functions

static newContentsKV (array $contents, ?SourceRange $tsr)
 Helper: return a new contents KV.
 
static trimContentsKV (KV $contents)
 Trim whitespace from both sides of a contents KV.
 
static newFromJsonArray (array $json)
 
static splitContentsBy (string|array|callable $sep, KV $contents, int $limit=-1)
 Split a contents KV by a string or a function.
 
static printContents ( $contents, bool $pretty=true)
 Pretty-print a contents KV on multiple lines.
 
- Static Public Member Functions inherited from Wikimedia\Parsoid\Tokens\Token
static jsonClassHintFor (string $keyName)
 
static hint ()
 
static getToken ( $input)
 Get a token from some PHP structure.
 

Public Attributes

const CONTENTS_ATTR = 'mw:contents'
 
- Public Attributes inherited from Wikimedia\Parsoid\Tokens\Token
DataParsoid $dataParsoid
 
DataMw $dataMw = null
 
array $attribs = null
 

Protected Member Functions

 recomputeTsr ()
 
 printInternal (array &$result, string $prefix, bool $pretty)
 Pretty-print this PreprocTk token.
 
- Protected Member Functions inherited from Wikimedia\Parsoid\Tokens\Token
 __construct (?DataParsoid $dataParsoid, ?DataMw $dataMw)
 

Static Protected Member Functions

static printContentsInternal (array &$result, array $pieces, string $prefix, bool $pretty)
 

Detailed Description

Represents a preprocessor "piece".

Contents of this token are not fully parsed, only the boundary locations are known.

Member Function Documentation

◆ __clone()

Wikimedia\Parsoid\Tokens\PreprocTk::__clone ( )

Reimplemented from Wikimedia\Parsoid\Tokens\Token.

◆ getBarredArgs()

Wikimedia\Parsoid\Tokens\PreprocTk::getBarredArgs ( )

Split this token by | and return target and named args.

Returns
list<KV>

◆ getContents()

Wikimedia\Parsoid\Tokens\PreprocTk::getContents ( )
Returns
list<PreprocTk|string>

◆ getContentsKV()

Wikimedia\Parsoid\Tokens\PreprocTk::getContentsKV ( )
Returns
KV containing list<PreprocTk|string> as value

◆ jsonSerialize()

◆ newContentsKV()

static Wikimedia\Parsoid\Tokens\PreprocTk::newContentsKV ( array $contents,
?SourceRange $tsr )
static

Helper: return a new contents KV.

Parameters
list<PreprocTk|string>$contents
?SourceRange$tsr
Returns
KV with key set to self::CONTENTS_ATTR and given $contents as value.

◆ newFromJsonArray()

static Wikimedia\Parsoid\Tokens\PreprocTk::newFromJsonArray ( array $json)
static

◆ print()

Wikimedia\Parsoid\Tokens\PreprocTk::print ( $pretty = true)

Pretty-print a PreprocTk token.

Parameters
bool$prettyif true (default) the output will be on multiple lines. If false, the string result should be identical to the original "preprocessed" wikitext.
Returns
string

◆ printContents()

static Wikimedia\Parsoid\Tokens\PreprocTk::printContents ( $contents,
bool $pretty = true )
static

Pretty-print a contents KV on multiple lines.

Parameters
KV$contentsA contents KV containing a list<string|PreprocTk>
bool$prettyif true (default) the output will be on multiple lines. If false, the string result should be identical to the original "preprocessed" wikitext.
Returns
string

◆ printContentsInternal()

static Wikimedia\Parsoid\Tokens\PreprocTk::printContentsInternal ( array & $result,
array $pieces,
string $prefix,
bool $pretty )
staticprotected
Parameters
list<string>&$result
list<string|PreprocTk>$pieces A contents array
string$prefixIndentation prefix

◆ printInternal()

Wikimedia\Parsoid\Tokens\PreprocTk::printInternal ( array & $result,
string $prefix,
bool $pretty )
protected

Pretty-print this PreprocTk token.

Parameters
list<string>&$result An array of output lines.
string$prefixIndentation prefix

Reimplemented in Wikimedia\Parsoid\Tokens\PreprocAngleTk, Wikimedia\Parsoid\Tokens\PreprocHeadingTk, Wikimedia\Parsoid\Tokens\PreprocIgnoreTk, and Wikimedia\Parsoid\Tokens\PreprocPFragmentTk.

◆ setContents()

Wikimedia\Parsoid\Tokens\PreprocTk::setContents ( array $contents,
SourceRange $tsr )
Parameters
list<PreprocTk|string>$contents
SourceRange$tsr

◆ setContentsKV()

Wikimedia\Parsoid\Tokens\PreprocTk::setContentsKV ( KV $contents)
Parameters
KV$contents

◆ splitContentsBy()

static Wikimedia\Parsoid\Tokens\PreprocTk::splitContentsBy ( string|array|callable $sep,
KV $contents,
int $limit = -1 )
static

Split a contents KV by a string or a function.

Parameters
string|list<string>|callable(string,int):array$sep Either a separator string, or a list of separator alternatives, or else a function compatible with preg_split with the PREG_SPLIT_DELIM_CAPTURE flag; that is, returns a list of strings with the "splitter" string in odd indexes.
KV$contentsA contents KV, containing a list<string|PreprocTk>
int$limitA split limit, or -1 for "no limit" This is the number of splits permitted; the return array length will be 1 + 2*$limit.
Returns
list<KV> a list of contents KVs, with the "splitter" strings in odd indexes.

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