From 5a77aa959befc01327ecdc9f977767ab148db69f Mon Sep 17 00:00:00 2001 From: Subramanya Sastry Date: Thu, 8 Jun 2023 19:26:38 +0530 Subject: [PATCH] ParsoidExtensionAPI: Add method to process HTML embedded in attributes * Parsoid core cannot know anything about how extensions represent information in their DOM. We were missing an extension API method and config that lets extensions specify this information along with handlers to process embedded content. * This patch fills that above gap. * There is a FIXME in ContentUtils::shiftDSR which will be addressed in followup patches with this new functionality. Change-Id: If921ca471f25f21671a60c3f796fdf145267364d --- src/Parsoid/Cite.php | 8 +++++++- src/Parsoid/Ref.php | 11 +++++++++++ src/Parsoid/References.php | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Parsoid/Cite.php b/src/Parsoid/Cite.php index d2045952c..94198dad2 100644 --- a/src/Parsoid/Cite.php +++ b/src/Parsoid/Cite.php @@ -22,7 +22,10 @@ class Cite implements ExtensionModule { 'name' => 'ref', 'handler' => Ref::class, 'options' => [ - 'wt2html' => [ 'unpackOutput' => false ], + 'wt2html' => [ + 'unpackOutput' => false, + 'embedsHTMLInAttributes' => true + ], 'outputHasCoreMwDomSpecMarkup' => true ], ], @@ -30,6 +33,9 @@ class Cite implements ExtensionModule { 'name' => 'references', 'handler' => References::class, 'options' => [ + 'wt2html' => [ + 'embedsHTMLInAttributes' => true + ], 'html2wt' => [ 'format' => 'block' ], 'outputHasCoreMwDomSpecMarkup' => true ], diff --git a/src/Parsoid/Ref.php b/src/Parsoid/Ref.php index 8e36cd2f9..01c40b2af 100644 --- a/src/Parsoid/Ref.php +++ b/src/Parsoid/Ref.php @@ -3,6 +3,7 @@ declare( strict_types = 1 ); namespace Wikimedia\Parsoid\Ext\Cite; +use Closure; use Exception; use Wikimedia\Parsoid\DOM\DocumentFragment; use Wikimedia\Parsoid\DOM\Element; @@ -54,6 +55,16 @@ class Ref extends ExtensionTagHandler { ); } + /** @inheritDoc */ + public function processAttributeEmbeddedHTML( + ParsoidExtensionAPI $extApi, Element $elt, Closure $proc + ): void { + $dataMw = DOMDataUtils::getDataMw( $elt ); + if ( isset( $dataMw->body->html ) ) { + $dataMw->body->html = $proc( $dataMw->body->html ); + } + } + /** @inheritDoc */ public function lintHandler( ParsoidExtensionAPI $extApi, Element $ref, callable $defaultHandler diff --git a/src/Parsoid/References.php b/src/Parsoid/References.php index 28a2307e6..e39be4430 100644 --- a/src/Parsoid/References.php +++ b/src/Parsoid/References.php @@ -3,6 +3,7 @@ declare( strict_types = 1 ); namespace Wikimedia\Parsoid\Ext\Cite; +use Closure; use stdClass; use Wikimedia\Parsoid\Core\DomSourceRange; use Wikimedia\Parsoid\DOM\DocumentFragment; @@ -795,6 +796,16 @@ class References extends ExtensionTagHandler { return $domFragment; } + /** @inheritDoc */ + public function processAttributeEmbeddedHTML( + ParsoidExtensionAPI $extApi, Element $elt, Closure $proc + ): void { + $dataMw = DOMDataUtils::getDataMw( $elt ); + if ( isset( $dataMw->body->html ) ) { + $dataMw->body->html = $proc( $dataMw->body->html ); + } + } + /** @inheritDoc */ public function domToWikitext( ParsoidExtensionAPI $extApi, Element $node, bool $wrapperUnmodified