mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-09-23 18:29:39 +00:00
Add MathML interface to LocalChecker
In preparation for caching we store the MathML fragment returned by local checker. The rational is that the string serialization of the parse tree is better chachable as the parsetree. Change-Id: Ice2ef1f4f7b83ed187507d4d067f446603d0d6a5
This commit is contained in:
parent
a5eea48d1a
commit
fc425b977c
|
@ -13,6 +13,8 @@ class LocalChecker extends BaseChecker {
|
|||
private ?Message $error = null;
|
||||
private ?TexArray $parseTree = null;
|
||||
|
||||
private ?string $mathMl = null;
|
||||
|
||||
/**
|
||||
* @param string $tex the TeX input string to be checked
|
||||
* @param string $type the input type
|
||||
|
@ -55,4 +57,9 @@ class LocalChecker extends BaseChecker {
|
|||
public function getParseTree(): ?TexArray {
|
||||
return $this->parseTree;
|
||||
}
|
||||
|
||||
public function getPresentationMathMLFragment(): string {
|
||||
$this->mathMl ??= $this->parseTree->renderMML();
|
||||
return $this->mathMl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class MathNativeMML extends MathMathML {
|
|||
}
|
||||
|
||||
protected function doRender(): StatusValue {
|
||||
$presentation = $this->getChecker()->getParseTree()->renderMML();
|
||||
$presentation = $this->getChecker()->getPresentationMathMLFragment();
|
||||
$config = MediaWikiServices::getInstance()->getMainConfig();
|
||||
$attributes = [ 'class' => 'mwe-math-element' ];
|
||||
if ( $this->getID() !== '' ) {
|
||||
|
|
|
@ -94,4 +94,16 @@ class LocalCheckerTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertInstanceOf( TexArray::class, $parseTree );
|
||||
$this->assertSame( 0, $parseTree->getLength() );
|
||||
}
|
||||
|
||||
public function testGetMML() {
|
||||
$checker = new LocalChecker( 'e^{i \pi} + 1 = 0' );
|
||||
$mml = $checker->getPresentationMathMLFragment();
|
||||
$this->assertStringContainsString( '<mn>0</mn>', $mml );
|
||||
}
|
||||
|
||||
public function testGetMMLEmpty() {
|
||||
$checker = new LocalChecker( '' );
|
||||
$mml = $checker->getPresentationMathMLFragment();
|
||||
$this->assertSame( '', $mml );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue