getName() !== 'wikilink' && $contextTok->getName() !== 'extlink' && $t instanceof SelfclosingTagTk && $t->getName() === 'meta' && TokenUtils::hasTypeOf( $t, 'mw:Transclusion' ) ) { return true; } elseif ( $t instanceof TagTk || $t instanceof EndTagTk || $t instanceof SelfclosingTagTk ) { // Since we encountered a complex token, we'll process this // in a subpipeline. return false; } } // No complex tokens at all -- no need to spin up a new pipeline return true; } private function buildDOMFragment( Token $scopeToken ): TokenHandlerResult { $contentKV = $scopeToken->getAttributeKV( 'content' ); $content = $contentKV->v; if ( is_string( $content ) || $this->subpipelineUnnecessary( $content, $scopeToken->getAttributeV( 'contextTok' ) ) ) { // New pipeline not needed. Pass them through return new TokenHandlerResult( is_string( $content ) ? [ $content ] : $content ); } else { // Source offsets of content $srcOffsets = $contentKV->srcOffsets; // Without source offsets for the content, it isn't possible to // compute DSR and template wrapping in content. So, users of // mw:dom-fragment-token should always set offsets on content // that comes from the top-level document. Assert::invariant( $this->options['inTemplate'] || (bool)$srcOffsets, 'Processing top-level content without source offsets' ); $pipelineOpts = [ 'inlineContext' => $scopeToken->getAttributeV( 'inlineContext' ) === "1", 'expandTemplates' => $this->options['expandTemplates'], 'inTemplate' => $this->options['inTemplate'] ]; // Append EOF $content[] = new EOFTk(); // Process tokens $domFragment = PipelineUtils::processContentInPipeline( $this->env, $this->manager->getFrame(), // Append EOF $content, [ 'pipelineType' => 'expanded-tokens-to-fragment', 'pipelineOpts' => $pipelineOpts, 'srcOffsets' => $srcOffsets->value, 'sol' => true ] ); $toks = PipelineUtils::tunnelDOMThroughTokens( $this->env, $scopeToken, $domFragment, [ "pipelineOpts" => $pipelineOpts ] ); return new TokenHandlerResult( $toks ); } } /** * @inheritDoc */ public function onTag( Token $token ): ?TokenHandlerResult { return $token->getName() === 'mw:dom-fragment-token' ? $this->buildDOMFragment( $token ) : null; } }