mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
native: Add onMathRenderingResultRetrieved hook
Allow in depth analysis of rendering results in native mode with the same mechanism that is also used for other rendering modes. Change-Id: I4927f9bc683445f83ef7c29dc2a9298aa85ff4d0
This commit is contained in:
parent
9706ed33ba
commit
493a7ac9f0
|
@ -3,7 +3,10 @@
|
|||
namespace MediaWiki\Extension\Math\InputCheck;
|
||||
|
||||
use Exception;
|
||||
use MediaWiki\Extension\Math\Hooks\HookRunner;
|
||||
use MediaWiki\Extension\Math\MathRenderer;
|
||||
use MediaWiki\Extension\Math\TexVC\TexVC;
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
use Message;
|
||||
use WANObjectCache;
|
||||
|
||||
|
@ -20,6 +23,8 @@ class LocalChecker extends BaseChecker {
|
|||
private bool $purge = false;
|
||||
|
||||
private bool $isChecked = false;
|
||||
private ?MathRenderer $context = null;
|
||||
private ?HookContainer $hookContainer = null;
|
||||
|
||||
public function __construct( WANObjectCache $cache, $tex = '', string $type = 'tex' ) {
|
||||
$this->cache = $cache;
|
||||
|
@ -120,16 +125,33 @@ class LocalChecker extends BaseChecker {
|
|||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if ( $result['status'] === '+' ) {
|
||||
return [
|
||||
$result['mathml'] = $result['input']->renderMML();
|
||||
$out = [
|
||||
'status' => '+',
|
||||
'output' => $result['output'],
|
||||
'mathml' => $result['input']->renderMML()
|
||||
'mathml' => $result['mathml']
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
$out = [
|
||||
'status' => $result['status'],
|
||||
'error' => $result['error'],
|
||||
];
|
||||
}
|
||||
if ( $this->context !== null && $this->hookContainer !== null ) {
|
||||
$resultObject = (object)$result;
|
||||
( new HookRunner( $this->hookContainer ) )->onMathRenderingResultRetrieved(
|
||||
$this->context,
|
||||
$resultObject
|
||||
);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function setContext( ?MathRenderer $renderer ): void {
|
||||
$this->context = $renderer;
|
||||
}
|
||||
|
||||
public function setHookContainer( ?HookContainer $hookContainer ): void {
|
||||
$this->hookContainer = $hookContainer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ class MathNativeMML extends MathMathML {
|
|||
protected function doRender(): StatusValue {
|
||||
$checker = $this->getChecker();
|
||||
$checker->setPurge( $this->isPurge() );
|
||||
$checker->setContext( $this );
|
||||
$checker->setHookContainer( MediaWikiServices::getInstance()->getHookContainer() );
|
||||
$presentation = $checker->getPresentationMathMLFragment();
|
||||
$config = MediaWikiServices::getInstance()->getMainConfig();
|
||||
$attributes = [ 'class' => 'mwe-math-element' ];
|
||||
|
|
Loading…
Reference in a new issue