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
This commit is contained in:
Subramanya Sastry 2023-06-08 19:26:38 +05:30
parent 1e61376d59
commit 5a77aa959b
3 changed files with 29 additions and 1 deletions

View file

@ -22,7 +22,10 @@ class Cite implements ExtensionModule {
'name' => 'ref', 'name' => 'ref',
'handler' => Ref::class, 'handler' => Ref::class,
'options' => [ 'options' => [
'wt2html' => [ 'unpackOutput' => false ], 'wt2html' => [
'unpackOutput' => false,
'embedsHTMLInAttributes' => true
],
'outputHasCoreMwDomSpecMarkup' => true 'outputHasCoreMwDomSpecMarkup' => true
], ],
], ],
@ -30,6 +33,9 @@ class Cite implements ExtensionModule {
'name' => 'references', 'name' => 'references',
'handler' => References::class, 'handler' => References::class,
'options' => [ 'options' => [
'wt2html' => [
'embedsHTMLInAttributes' => true
],
'html2wt' => [ 'format' => 'block' ], 'html2wt' => [ 'format' => 'block' ],
'outputHasCoreMwDomSpecMarkup' => true 'outputHasCoreMwDomSpecMarkup' => true
], ],

View file

@ -3,6 +3,7 @@ declare( strict_types = 1 );
namespace Wikimedia\Parsoid\Ext\Cite; namespace Wikimedia\Parsoid\Ext\Cite;
use Closure;
use Exception; use Exception;
use Wikimedia\Parsoid\DOM\DocumentFragment; use Wikimedia\Parsoid\DOM\DocumentFragment;
use Wikimedia\Parsoid\DOM\Element; 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 */ /** @inheritDoc */
public function lintHandler( public function lintHandler(
ParsoidExtensionAPI $extApi, Element $ref, callable $defaultHandler ParsoidExtensionAPI $extApi, Element $ref, callable $defaultHandler

View file

@ -3,6 +3,7 @@ declare( strict_types = 1 );
namespace Wikimedia\Parsoid\Ext\Cite; namespace Wikimedia\Parsoid\Ext\Cite;
use Closure;
use stdClass; use stdClass;
use Wikimedia\Parsoid\Core\DomSourceRange; use Wikimedia\Parsoid\Core\DomSourceRange;
use Wikimedia\Parsoid\DOM\DocumentFragment; use Wikimedia\Parsoid\DOM\DocumentFragment;
@ -795,6 +796,16 @@ class References extends ExtensionTagHandler {
return $domFragment; 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 */ /** @inheritDoc */
public function domToWikitext( public function domToWikitext(
ParsoidExtensionAPI $extApi, Element $node, bool $wrapperUnmodified ParsoidExtensionAPI $extApi, Element $node, bool $wrapperUnmodified