diff --git a/src/Parsoid/index.php b/src/Parsoid/index.php index 7a65df3e9..9d41c841e 100644 --- a/src/Parsoid/index.php +++ b/src/Parsoid/index.php @@ -10,8 +10,6 @@ namespace Parsoid; -use Parsoid\domino as domino; - $ParsoidExtApi = $module->parent->require( './extapi.js' )->versionCheck( '^0.10.0' ); $temp0 = @@ -111,7 +109,9 @@ Ref::prototype::serialHandler = [ // n.b. this is going to drop any diff markers but since // the dom differ doesn't traverse into extension content // none should exist anyways. - $html = ContentUtils::ppToXML( $bodyElt, [ 'innerXML' => true ] ); + DOMDataUtils::visitAndStoreDataAttribs( $bodyElt ); + $html = ContentUtils::toXML( $bodyElt, [ 'innerXML' => true ] ); + DOMDataUtils::visitAndLoadDataAttribs( $bodyElt ); } else { // Some extra debugging for VisualEditor $extraDebug = ''; @@ -346,11 +346,7 @@ function References( $cite ) { $this->cite = $cite; } -$dummyDoc = domino::createDocument(); - -$createReferences = function ( $env, $body, $refsOpts, $modifyDp, $autoGenerated ) use ( &$dummyDoc, &$DOMUtils, &$DOMDataUtils ) { - $doc = ( $body ) ? $body->ownerDocument : $dummyDoc; - +$createReferences = function ( $env, $doc, $body, $refsOpts, $modifyDp, $autoGenerated ) use ( &$DOMUtils, &$DOMDataUtils ) { $ol = $doc->createElement( 'ol' ); $ol->classList->add( 'mw-references' ); $ol->classList->add( 'references' ); @@ -409,7 +405,7 @@ References::prototype::toDOM = function ( $state, $content, $args ) use ( &$Pars ], TokenUtils::kvToHash( $args, true ) ); - $frag = $createReferences( $state->env, $doc->body, $refsOpts, function ( $dp ) use ( &$state ) { + $frag = $createReferences( $state->env, $doc, $doc->body, $refsOpts, function ( $dp ) use ( &$state ) { $dp->src = $state->extToken->getAttribute( 'source' ); // Redundant - also present on doc.body.firstChild, but feels cumbersome to use $dp->selfClose = $state->extToken->dataAttribs->selfClose; @@ -448,7 +444,7 @@ References::prototype::extractRefFromNode = function ( $node, $refsData, $cite, $cDp = DOMDataUtils::getDataParsoid( $c ); $refDmw = DOMDataUtils::getDataMw( $c ); if ( !$cDp->empty && hasRef( $c ) ) { // nested ref-in-ref - $_processRefs( $cite, $refsData, $c ); + $_processRefs( $env, $cite, $refsData, $c ); } DOMDataUtils::visitAndStoreDataAttribs( $c ); @@ -626,8 +622,8 @@ References::prototype::insertMissingReferencesIntoDOM = function ( $refsData, $n $env = $refsData->env; $doc = $node->ownerDocument; - $refsData->refGroups->forEach( function ( $refsValue, $refsGroup ) use ( &$createReferences, &$env, &$node, &$doc, &$refsData ) { - $frag = $createReferences( $env, null, [ + $refsData->refGroups->forEach( function ( $refsValue, $refsGroup ) use ( &$createReferences, &$env, &$doc, &$node, &$refsData ) { + $frag = $createReferences( $env, $doc, null, [ 'group' => $refsGroup, 'responsive' => null ], function ( $dp ) { @@ -733,7 +729,7 @@ $_processRefsInReferences = function ( $cite, $refsData, $node, $referencesId, } }; -$_processRefs = function ( $cite, $refsData, $node ) use ( &$DOMUtils, &$WTUtils, &$DOMDataUtils, &$_processRefsInReferences, &$ContentUtils, &$_processRefs ) { +$_processRefs = function ( $env, $cite, $refsData, $node ) use ( &$DOMUtils, &$WTUtils, &$DOMDataUtils, &$_processRefsInReferences, &$ContentUtils, &$_processRefs ) { $child = $node->firstChild; while ( $child !== null ) { $nextChild = $child->nextSibling; @@ -781,13 +777,13 @@ $_processRefs = function ( $cite, $refsData, $node ) use ( &$DOMUtils, &$WTUtils if ( $caption ) { // Extract the caption HTML, build the DOM, process refs, // serialize to HTML, update the caption HTML. - $captionDOM = ContentUtils::ppToDOM( $caption ); - $_processRefs( $cite, $refsData, $captionDOM ); + $captionDOM = ContentUtils::ppToDOM( $env, $caption ); + $_processRefs( $env, $cite, $refsData, $captionDOM ); $dmw->caption = ContentUtils::ppToXML( $captionDOM, [ 'innerXML' => true ] ); } } if ( $child->hasChildNodes() ) { - $_processRefs( $cite, $refsData, $child ); + $_processRefs( $env, $cite, $refsData, $child ); } } } @@ -843,7 +839,7 @@ $Cite = function () { Cite::prototype::_wt2htmlPostProcessor = function ( $body, $env, $options, $atTopLevel ) use ( &$_processRefs ) { if ( $atTopLevel ) { $refsData = new ReferencesData( $env ); - $_processRefs( $this, $refsData, $body ); + $_processRefs( $env, $this, $refsData, $body ); $this->references->insertMissingReferencesIntoDOM( $refsData, $body ); } };