mediawiki-extensions-Cite/src/Parsoid/RefProcessor.php

44 lines
1 KiB
PHP
Raw Normal View History

<?php
declare( strict_types = 1 );
namespace Wikimedia\Parsoid\Ext\Cite;
use DOMElement;
use DOMNode;
use Wikimedia\Parsoid\Ext\DOMProcessor;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
/**
* wt -> html DOM PostProcessor
*/
class RefProcessor extends DOMProcessor {
Start untangling Parsoid internals from extensions * In this patch, toDOM, fromDOM, and DOM postprocessor extension methods all get a ParsoidExtensionAPI object. These API objects are constructed at the appropriate times in the wt2html and html2wt pipelines. * Got rid of direct references to SerializerState from fromDOM methods in extensions. * Exposed generic serialization and wikitext escaping methods in ParsoidExtensionAPI for extensions to leverage. The implementation of these methods is partial and only supports current usage of extensions in Parsoid's repo. This will need to be fully fleshed out going forward. * Stopped exposing wt2html options in toto and provided more specific convenience methods. * Reduced direct access to the Env object in a few more places. * Cite has code to inspect embedded HTML in data attributes of a node. Moved this code out of Cite into ParsoidExtensionAPI which reduces knowledge that extensions need. Unlike the other cleanups, this one is more of a convenience method since this code only requires knowledge of a publicly published spec. But, nevertheless an useful cleanup since it simplifies Cite's complexity just a bit. * More followup work is needed. - before/after methods should be eliminated in favour of a config flag that implements the inline/block layout option. Once this is done, extensions will no longer need direct access to the SerializerState internal object. - Env exposure should be reduced. - Provide access to Sanitizer via ParsoidExtensionAPI instead of needing extensions to directly import it. - It should be possible to eliminate the need for extensions to know about DSR / DSR-shifting and do it automatically via some high-level conceptual flag. - It might also be possible to infer source offsets directly via args instead of passing that explicitly. - Should we provide a convenience helper class with access to all the src/Utils/* methods? Bug: T242746 Change-Id: I7ffb5aa52a84854a9d363a0e8f1ce650241f1c41
2020-01-17 13:12:15 +00:00
/**
* @inheritDoc
Start untangling Parsoid internals from extensions * In this patch, toDOM, fromDOM, and DOM postprocessor extension methods all get a ParsoidExtensionAPI object. These API objects are constructed at the appropriate times in the wt2html and html2wt pipelines. * Got rid of direct references to SerializerState from fromDOM methods in extensions. * Exposed generic serialization and wikitext escaping methods in ParsoidExtensionAPI for extensions to leverage. The implementation of these methods is partial and only supports current usage of extensions in Parsoid's repo. This will need to be fully fleshed out going forward. * Stopped exposing wt2html options in toto and provided more specific convenience methods. * Reduced direct access to the Env object in a few more places. * Cite has code to inspect embedded HTML in data attributes of a node. Moved this code out of Cite into ParsoidExtensionAPI which reduces knowledge that extensions need. Unlike the other cleanups, this one is more of a convenience method since this code only requires knowledge of a publicly published spec. But, nevertheless an useful cleanup since it simplifies Cite's complexity just a bit. * More followup work is needed. - before/after methods should be eliminated in favour of a config flag that implements the inline/block layout option. Once this is done, extensions will no longer need direct access to the SerializerState internal object. - Env exposure should be reduced. - Provide access to Sanitizer via ParsoidExtensionAPI instead of needing extensions to directly import it. - It should be possible to eliminate the need for extensions to know about DSR / DSR-shifting and do it automatically via some high-level conceptual flag. - It might also be possible to infer source offsets directly via args instead of passing that explicitly. - Should we provide a convenience helper class with access to all the src/Utils/* methods? Bug: T242746 Change-Id: I7ffb5aa52a84854a9d363a0e8f1ce650241f1c41
2020-01-17 13:12:15 +00:00
*/
public function wtPostprocess(
ParsoidExtensionAPI $extApi, DOMNode $node, array $options, bool $atTopLevel
): void {
if ( $atTopLevel ) {
$refsData = new ReferencesData();
References::processRefs( $extApi, $refsData, $node );
References::insertMissingReferencesIntoDOM( $extApi, $refsData, $node );
}
}
/**
* html -> wt DOM PreProcessor
*
* Nothing to do right now.
*
* But, for example, as part of some future functionality, this could be used to
* reconstitute page-level information from local annotations left behind by editing clients.
*
* @param ParsoidExtensionAPI $extApi
* @param DOMElement $root
*/
public function htmlPreprocess( ParsoidExtensionAPI $extApi, DOMElement $root ): void {
// TODO
}
}