Parsoid
A bidirectional parser between wikitext and HTML5
Parsoid\Utils\PipelineUtils Class Reference

This file contains parsing pipeline related utilities. More...

Static Public Member Functions

static getDOMFragmentToken ( $content, SourceRange $srcOffsets, array $opts=[])
 Creates a dom-fragment-token for processing 'content' (an array of tokens) in its own subpipeline all the way to DOM. More...
 
static processContentInPipeline (Env $env, Frame $frame, $content, array $opts)
 Processes content (wikitext, array of tokens, whatever) in its own pipeline based on options. More...
 
static expandValueToDOM (Env $env, Frame $frame, array $v, bool $expandTemplates, bool $inTemplate)
 Expands value all the way to DOM. More...
 
static expandValuesToDOM (Env $env, $frame, array $vals, bool $expandTemplates, bool $inTemplate)
 
static getWrapperTokens (array $nodes, array $opts)
 Get tokens representing a DOM forest (from transclusions, extensions, whatever that were generated as part of a separate processing pipeline) in the token stream. More...
 
static encapsulateExpansionHTML (Env $env, Token $token, array $expansion, array $opts=[])
 Generates wrapper tokens for a HTML expansion – the wrapper tokens are placeholders that adequately represent semantics of the HTML DOM for the purposes of additional token transformations that will be applied to them. More...
 
static addSpanWrappers (DOMNodeList $nodes)
 Wrap text and comment nodes in a node list into spans, so that all top-level nodes are elements. More...
 
static tunnelDOMThroughTokens (Env $env, Token $token, DOMElement $body, array $opts)
 Convert a HTML5 DOM into a mw:DOMFragment and generate appropriate tokens to insert into the token stream for further processing. More...
 
static makeExpansion (Env $env, array $nodes)
 
static extractExpansions (Env $env, DOMElement $body)
 Extract transclusion and extension expansions from a DOM, and return them in a structure like this: { transclusions: { 'key1': { html: 'html1', nodes: [<node1>, <node2>] } }, extensions: { 'key2': { html: 'html2', nodes: [<node1>, <node2>] } }, files: { 'key3': { html: 'html3', nodes: [<node1>, <node2>] } } }. More...
 

Detailed Description

This file contains parsing pipeline related utilities.

Member Function Documentation

◆ addSpanWrappers()

static Parsoid\Utils\PipelineUtils::addSpanWrappers ( DOMNodeList  $nodes)
static

Wrap text and comment nodes in a node list into spans, so that all top-level nodes are elements.

Parameters
DOMNodeList$nodesList of DOM nodes to wrap, mix of node types.

◆ encapsulateExpansionHTML()

static Parsoid\Utils\PipelineUtils::encapsulateExpansionHTML ( Env  $env,
Token  $token,
array  $expansion,
array  $opts = [] 
)
static

Generates wrapper tokens for a HTML expansion – the wrapper tokens are placeholders that adequately represent semantics of the HTML DOM for the purposes of additional token transformations that will be applied to them.

Parameters
Env$envThe active environment/context.
Token$tokenThe token that generated the DOM.
array$expansion
  • string html HTML of the expansion.
  • DOMNode[] nodes Outermost nodes of the HTML.
array$opts
  • SourceRange tsr The TSR to set on the generated tokens. This TSR is used to compute DSR on the placeholder tokens. The computed DSR is transferred over to the unpacked DOM if setDSR is true (see below).
  • bool setDSR When the DOM fragment is unpacked, this option governs whether the DSR from the placeholder node is transferred over to the unpacked DOM or not. For example: Cite, reused transclusions.
  • bool fromCache
  • array pipelineOpts
  • bool sealFragment
  • string wrapperName
Returns
Token[]

◆ expandValuesToDOM()

static Parsoid\Utils\PipelineUtils::expandValuesToDOM ( Env  $env,
  $frame,
array  $vals,
bool  $expandTemplates,
bool  $inTemplate 
)
static
Parameters
Env$envThe environment/context for the expansion.
Frame$frameThe parent frame within which the expansion is taking place. Used for template expansion and source text tracking.
array$valsArray of values to expand. Non-array elements of $vals are passed back unmodified. If an array element, it is expected to be an associative array with a "html" property. The html property is expanded to DOM only if it is an array (of tokens).
bool$expandTemplatesShould any templates encountered here be expanded (usually false for nested templates since they are never directly editable).
bool$inTemplateUnexpanded templates can occur in the content of extension tags.
Returns
array

◆ expandValueToDOM()

static Parsoid\Utils\PipelineUtils::expandValueToDOM ( Env  $env,
Frame  $frame,
array  $v,
bool  $expandTemplates,
bool  $inTemplate 
)
static

Expands value all the way to DOM.

Parameters
Env$envThe environment/context for the expansion.
Frame$frameThe parent frame within which the expansion is taking place. Used for template expansion and source text tracking.
array$vThe value to process. The value is expected to be an associative array with a "html" property. The html property is expanded to DOM only if it is an array (of tokens). Non-arrays are passed back unexpanded.
bool$expandTemplatesShould any templates encountered here be expanded (usually false for nested templates since they are never directly editable).
bool$inTemplateUnexpanded templates can occur in the content of extension tags.
Returns
array

◆ extractExpansions()

static Parsoid\Utils\PipelineUtils::extractExpansions ( Env  $env,
DOMElement  $body 
)
static

Extract transclusion and extension expansions from a DOM, and return them in a structure like this: { transclusions: { 'key1': { html: 'html1', nodes: [<node1>, <node2>] } }, extensions: { 'key2': { html: 'html2', nodes: [<node1>, <node2>] } }, files: { 'key3': { html: 'html3', nodes: [<node1>, <node2>] } } }.

Parameters
Env$env
DOMElement$body
Returns
array

◆ getDOMFragmentToken()

static Parsoid\Utils\PipelineUtils::getDOMFragmentToken (   $content,
SourceRange  $srcOffsets,
array  $opts = [] 
)
static

Creates a dom-fragment-token for processing 'content' (an array of tokens) in its own subpipeline all the way to DOM.

These tokens will be processed by their own handler (DOMFragmentBuilder) in the last stage of the async pipeline.

srcOffsets should always be provided to process top-level page content in a subpipeline. Without it, DSR computation and template wrapping cannot be done in the subpipeline. While unpackDOMFragment can do this on unwrapping, that can be a bit fragile and makes dom-fragments a leaky abstraction by leaking subpipeline processing into the top-level pipeline.

Parameters
Token[]|string$content The array of tokens to process.
SourceRange$srcOffsetsWikitext source offsets (start/end) of these tokens.
array$optsParsing options.
  • Token token The token that generated the content.
  • bool inlineContext Is this DOM fragment used in an inline context?
  • bool inPHPBlock Is this DOM fragment used inside a "PHP Block" FIXME: This exists primarily for backward compatibility reasons and is likely to eventually go away.
Returns
SelfclosingTagTk

◆ getWrapperTokens()

static Parsoid\Utils\PipelineUtils::getWrapperTokens ( array  $nodes,
array  $opts 
)
static

Get tokens representing a DOM forest (from transclusions, extensions, whatever that were generated as part of a separate processing pipeline) in the token stream.

These tokens will tunnel the subtree through the token processing while preserving token stream semantics as if the DOM had been converted to tokens.

Parameters
DOMNode[]$nodes List of DOM nodes that need to be tunneled through.
array$opts
See also
encapsulateExpansionHTML's doc. for more info about these options.
Returns
Token[] List of token representatives.

◆ makeExpansion()

static Parsoid\Utils\PipelineUtils::makeExpansion ( Env  $env,
array  $nodes 
)
static
Parameters
Env$env
DOMNode[]$nodes
Returns
array

◆ processContentInPipeline()

static Parsoid\Utils\PipelineUtils::processContentInPipeline ( Env  $env,
Frame  $frame,
  $content,
array  $opts 
)
static

Processes content (wikitext, array of tokens, whatever) in its own pipeline based on options.

Parameters
Env$envThe environment/context for the expansion.
Frame$frameThe parent frame within which the expansion is taking place. Used for template expansion and source text tracking.
string|Token|Token[]$content This could be wikitext or single token or an array of tokens. How this content is processed depends on what kind of pipeline is constructed specified by opts.
array$optsProcessing options that specify pipeline-type, opts, and callbacks.
  • string pipelineType
  • array pipelineOpts
  • array tplArgs - if set, defines parameters for the child frame
  • string tplArgs.name
  • array tplArgs.attribs
  • string srcText - if set, defines the source text for the expansion
  • SourceRange srcOffsets - if set, defines the range within the source text that $content corresponds to
  • bool sol
Returns
Token[]|DOMDocument (depending on pipeline type)

◆ tunnelDOMThroughTokens()

static Parsoid\Utils\PipelineUtils::tunnelDOMThroughTokens ( Env  $env,
Token  $token,
DOMElement  $body,
array  $opts 
)
static

Convert a HTML5 DOM into a mw:DOMFragment and generate appropriate tokens to insert into the token stream for further processing.

The DOMPostProcessor will unpack the fragment and insert the HTML back into the DOM.

Parameters
Env$envThe active environment/context.
Token$tokenThe token that generated the DOM.
DOMElement$bodyThe DOM that the token expanded to.
array$optsOptions to be passed onto the encapsulation code See encapsulateExpansionHTML's doc. for more info about these options.
Returns
Token[]

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