All extension DOM processors should extend Ext\DOMProcessor

Change-Id: Ide9700747b3ecea9da59911c6eb342569be4c9b8
This commit is contained in:
C. Scott Ananian 2020-04-21 19:22:30 -04:00 committed by Subramanya Sastry
parent b4aefae357
commit 51c211047a
2 changed files with 9 additions and 19 deletions

View file

@ -17,8 +17,7 @@ class Cite implements ExtensionModule {
return [ return [
'name' => 'Cite', 'name' => 'Cite',
'domProcessors' => [ 'domProcessors' => [
'wt2htmlPostProcessor' => RefProcessor::class, RefProcessor::class,
'html2wtPreProcessor' => [ self::class, 'html2wtPreProcessor' ],
], ],
'tags' => [ 'tags' => [
[ [

View file

@ -4,35 +4,26 @@ declare( strict_types = 1 );
namespace Wikimedia\Parsoid\Ext\Cite; namespace Wikimedia\Parsoid\Ext\Cite;
use DOMElement; use DOMElement;
use Wikimedia\Parsoid\Ext\DOMProcessor;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
/** /**
* wt -> html DOM PostProcessor * wt -> html DOM PostProcessor
*/ */
class RefProcessor { class RefProcessor extends DOMProcessor {
/** @var ParsoidExtensionAPI Provides post-processing support */
private $extApi;
/** /**
* @param ParsoidExtensionAPI $extApi * @inheritDoc
*/ */
public function __construct( ParsoidExtensionAPI $extApi ) { public function wtPostprocess(
$this->extApi = $extApi;
}
/**
* @param ParsoidExtensionAPI $extApi
* @param DOMElement $body
* @param array $options
* @param bool $atTopLevel
*/
public function run(
ParsoidExtensionAPI $extApi, DOMElement $body, array $options, bool $atTopLevel ParsoidExtensionAPI $extApi, DOMElement $body, array $options, bool $atTopLevel
): void { ): void {
if ( $atTopLevel ) { if ( $atTopLevel ) {
$refsData = new ReferencesData(); $refsData = new ReferencesData();
References::processRefs( $this->extApi, $refsData, $body ); References::processRefs( $extApi, $refsData, $body );
References::insertMissingReferencesIntoDOM( $this->extApi, $refsData, $body ); References::insertMissingReferencesIntoDOM( $extApi, $refsData, $body );
} }
} }
// FIXME: should implement an htmlPreprocess method as well.
} }