Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Wt2Html\TT\TokenCollector Class Reference

Small utility class that encapsulates the common 'collect all tokens starting from a token of type x until token of type y or (optionally) the end-of-input'. More...

+ Inheritance diagram for Wikimedia\Parsoid\Wt2Html\TT\TokenCollector:
+ Collaboration diagram for Wikimedia\Parsoid\Wt2Html\TT\TokenCollector:

Public Member Functions

 __construct (TokenTransformManager $manager, array $options)
 
 onTag (Token $token)
 This handler is called for tokens that are not EOFTk or NLTk tokens.The handler may choose to process only specific kinds of tokens. For example, a list handler may only process 'listitem' TagTk tokens.
Parameters
Token$tokenToken to be processed
Returns
TokenHandlerResult|null A TokenHandlerResult, or null to efficiently indicate that the input token is unchanged.

 
 onEnd (EOFTk $token)
 This handler is called for EOF tokens only.
Parameters
EOFTk$tokenEOF token to be processed
Returns
TokenHandlerResult|null A TokenHandlerResult, or null to efficiently indicate that the input token is unchanged.

 
 onAny ( $token)
 This handler is called for all tokens in the token stream except if (a) The more specific handlers above modified the token (b) the more specific handlers (onTag, onEnd, onNewline) have set the skip flag in their return values.(c) this handlers 'active' flag is set to false (can be set by any of the handlers).
Parameters
Token | string$tokenToken to be processed
Returns
TokenHandlerResult|null A TokenHandlerResult, or null to efficiently indicate that the input token is unchanged.

 
- Public Member Functions inherited from Wikimedia\Parsoid\Wt2Html\TT\TokenHandler
 setPipelineId (int $id)
 
 resetState (array $options)
 Resets any internal state for this token handler.
 
 isDisabled ()
 Is this transformer disabled?
 
 onNewline (NlTk $token)
 This handler is called for newline tokens only.
 
 process ( $tokens)
 Push an input array of tokens through the transformer and return the transformed tokens.
 

Static Public Member Functions

static buildMetaToken (TokenTransformManager $manager, string $tokenName, bool $isEnd, SourceRange $tsr, ?string $src)
 This helper function will build a meta token in the right way for these tags.
 

Protected Member Functions

 type ()
 Token type to register for ('tag', 'text' etc)
 
 name ()
 (optional, only for token type 'tag'): tag name.
 
 toEnd ()
 Match the 'end' tokens as closing tag as well (accept unclosed sections).
 
 ackEnd ()
 Whether to transform unmatched end tags.
 
 transformation (array $array)
 When an end delimiter is found, this function is called with the collected token array including the start and end delimiters.
 

Static Protected Member Functions

static buildStrippedMetaToken (TokenTransformManager $manager, string $tokenName, Token $startDelim, ?Token $endDelim)
 

Protected Attributes

array $scopeStack = []
 
- Protected Attributes inherited from Wikimedia\Parsoid\Wt2Html\TT\TokenHandler
 $env
 
 $manager
 
 $pipelineId
 
 $options
 
bool $disabled = false
 This is set if the token handler is disabled for the entire pipeline.
 
bool $onAnyEnabled = true
 This is set/reset by the token handlers at various points in the token stream based on what is encountered.
 
 $atTopLevel = false
 

Detailed Description

Small utility class that encapsulates the common 'collect all tokens starting from a token of type x until token of type y or (optionally) the end-of-input'.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::__construct ( TokenTransformManager $manager,
array $options )
Parameters
TokenTransformManager$managermanager enviroment
array$optionsvarious configuration options

Reimplemented from Wikimedia\Parsoid\Wt2Html\TT\TokenHandler.

Reimplemented in Wikimedia\Parsoid\Wt2Html\TT\IncludeOnly, and Wikimedia\Parsoid\Wt2Html\TT\NoInclude.

Member Function Documentation

◆ ackEnd()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::ackEnd ( )
abstractprotected

Whether to transform unmatched end tags.

If this returns true, unbalanced end tags will be passed to transform(). If it returns false, they will be left in the token stream unmodified.

Returns
bool

Reimplemented in Wikimedia\Parsoid\Wt2Html\TT\IncludeOnly, and Wikimedia\Parsoid\Wt2Html\TT\NoInclude.

◆ buildMetaToken()

static Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::buildMetaToken ( TokenTransformManager $manager,
string $tokenName,
bool $isEnd,
SourceRange $tsr,
?string $src )
static

This helper function will build a meta token in the right way for these tags.

Parameters
TokenTransformManager$manager
string$tokenName
bool$isEnd
SourceRange$tsr
?string$src
Returns
SelfclosingTagTk

◆ name()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::name ( )
abstractprotected

(optional, only for token type 'tag'): tag name.

Returns
string

Reimplemented in Wikimedia\Parsoid\Wt2Html\TT\IncludeOnly, and Wikimedia\Parsoid\Wt2Html\TT\NoInclude.

◆ onAny()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::onAny ( $token)

This handler is called for all tokens in the token stream except if (a) The more specific handlers above modified the token (b) the more specific handlers (onTag, onEnd, onNewline) have set the skip flag in their return values.(c) this handlers 'active' flag is set to false (can be set by any of the handlers).

Parameters
Token | string$tokenToken to be processed
Returns
TokenHandlerResult|null A TokenHandlerResult, or null to efficiently indicate that the input token is unchanged.

Reimplemented from Wikimedia\Parsoid\Wt2Html\TT\TokenHandler.

◆ onEnd()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::onEnd ( EOFTk $token)

This handler is called for EOF tokens only.

Parameters
EOFTk$tokenEOF token to be processed
Returns
TokenHandlerResult|null A TokenHandlerResult, or null to efficiently indicate that the input token is unchanged.

Reimplemented from Wikimedia\Parsoid\Wt2Html\TT\TokenHandler.

◆ onTag()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::onTag ( Token $token)

This handler is called for tokens that are not EOFTk or NLTk tokens.The handler may choose to process only specific kinds of tokens. For example, a list handler may only process 'listitem' TagTk tokens.

Parameters
Token$tokenToken to be processed
Returns
TokenHandlerResult|null A TokenHandlerResult, or null to efficiently indicate that the input token is unchanged.

Reimplemented from Wikimedia\Parsoid\Wt2Html\TT\TokenHandler.

◆ toEnd()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::toEnd ( )
abstractprotected

Match the 'end' tokens as closing tag as well (accept unclosed sections).

Returns
bool

Reimplemented in Wikimedia\Parsoid\Wt2Html\TT\IncludeOnly, and Wikimedia\Parsoid\Wt2Html\TT\NoInclude.

◆ transformation()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::transformation ( array $array)
abstractprotected

When an end delimiter is found, this function is called with the collected token array including the start and end delimiters.

The subclass should transform it and return the result.

Parameters
array$array
Returns
TokenHandlerResult

Reimplemented in Wikimedia\Parsoid\Wt2Html\TT\IncludeOnly, and Wikimedia\Parsoid\Wt2Html\TT\NoInclude.

◆ type()

Wikimedia\Parsoid\Wt2Html\TT\TokenCollector::type ( )
abstractprotected

Token type to register for ('tag', 'text' etc)

Returns
string

Reimplemented in Wikimedia\Parsoid\Wt2Html\TT\IncludeOnly, and Wikimedia\Parsoid\Wt2Html\TT\NoInclude.


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