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

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

Static Public Member Functions

static pFragmentToParsoidFragmentMarkers (PFragment $fragment)
 Returns a wikitext string with embedded parsoid fragment markers, as well as a mapping from the marker IDs to PFragment objects.
 
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.
 
static processContentInPipeline (Env $env, Frame $frame, $content, array $opts)
 Processes content (wikitext, array of tokens, whatever) in its own pipeline based on options.
 
static expandAttrValueToDOM (Env $env, Frame $frame, array $v, bool $expandTemplates, bool $inTemplate)
 Expands value all the way to DOM.
 
static expandAttrValuesToDOM (Env $env, $frame, array $vals, bool $expandTemplates, bool $inTemplate)
 
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.
 
static addSpanWrappers ( $nodes, ?Node $startAt=null, ?Node $stopAt=null)
 Wrap text and comment nodes in a node list into spans, so that all top-level nodes are elements.
 
static tunnelDOMThroughTokens (Env $env, Token $token, DocumentFragment $domFragment, array $opts)
 Convert a HTML5 DOM into a mw:DOMFragment and generate appropriate tokens to insert into the token stream for further processing.
 
static makeExpansion (Env $env, DocumentFragment $domFragment)
 
static extractExpansions (Env $env, Element $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>] } } }.
 
static fetchHTML (Env $env, string $source)
 Fetches output of encapsulations that return HTML from the legacy parser.
 

Public Attributes

const PARSOID_FRAGMENT_PREFIX = '{{#parsoid\0fragment:'
 

Detailed Description

This file contains parsing pipeline related utilities.

Member Function Documentation

◆ addSpanWrappers()

static Wikimedia\Parsoid\Utils\PipelineUtils::addSpanWrappers ( $nodes,
?Node $startAt = null,
?Node $stopAt = null )
static

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

Parameters
NodeList$nodesList of DOM nodes to wrap, mix of node types.
?Node$startAt
?Node$stopAt

◆ encapsulateExpansionHTML()

static Wikimedia\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.
  • DocumentFragment domFragment 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 unpackOutput
  • string wrapperName
Returns
array<Token|string>

◆ expandAttrValuesToDOM()

static Wikimedia\Parsoid\Utils\PipelineUtils::expandAttrValuesToDOM ( 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

◆ expandAttrValueToDOM()

static Wikimedia\Parsoid\Utils\PipelineUtils::expandAttrValueToDOM ( 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 Wikimedia\Parsoid\Utils\PipelineUtils::extractExpansions ( Env $env,
Element $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
Element$body
Returns
array

◆ getDOMFragmentToken()

static Wikimedia\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
string|Token|array<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?
Returns
SelfclosingTagTk

◆ pFragmentToParsoidFragmentMarkers()

static Wikimedia\Parsoid\Utils\PipelineUtils::pFragmentToParsoidFragmentMarkers ( PFragment $fragment)
static

Returns a wikitext string with embedded parsoid fragment markers, as well as a mapping from the marker IDs to PFragment objects.

Returns
array{0:string,1:array<string,PFragment>} A array consisting of the wikitext string, followed by the id-to-PFragment map.

◆ processContentInPipeline()

static Wikimedia\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|array<Token|string>|DocumentFragment|PFragment$content 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']
    • KV[] 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 Whether tokens should be processed in start-of-line context.
  • bool toplevel Whether the pipeline is considered atTopLevel
Returns
array<Token|string>|DocumentFragment (depending on pipeline type)

◆ tunnelDOMThroughTokens()

static Wikimedia\Parsoid\Utils\PipelineUtils::tunnelDOMThroughTokens ( Env $env,
Token $token,
DocumentFragment $domFragment,
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.
DocumentFragment$domFragmentThe 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
array<Token|string>

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