Fix colors

* some tests for checking colors

Bug: T327391
Change-Id: I437f8d72834f3cca7c21f97841ee4da2f1f36ed5
This commit is contained in:
Stegmujo 2023-03-22 09:01:32 +00:00
parent 41eddd141b
commit 5de6683c05
No known key found for this signature in database
GPG key ID: FEFA628F883FAE29
3 changed files with 21 additions and 6 deletions

View file

@ -73,11 +73,6 @@ class Literal extends TexNode {
if ( $ret ) {
return $ret;
}
// Sieve for Colors
$ret = $bm->checkAndParseColor( $input, $this, $arguments, $operatorContent );
if ( $ret ) {
return $ret;
}
// Sieve for Makros
$ret = BaseMethods::checkAndParse( $input, $arguments, $operatorContent, $this );

View file

@ -5,6 +5,7 @@ declare( strict_types = 1 );
namespace MediaWiki\Extension\Math\TexVC\Nodes;
use InvalidArgumentException;
use MediaWiki\Extension\Math\TexVC\MMLmappings\BaseMappings;
use MediaWiki\Extension\Math\TexVC\MMLmappings\Util\MMLParsingUtil;
use MediaWiki\Extension\Math\TexVC\MMLmappings\Util\MMLutil;
use MediaWiki\Extension\Math\TexVC\MMLnodes\MMLmo;
@ -256,7 +257,8 @@ class TexArray extends TexNode {
$displayedColor = $state["colorDefinitions"][$currentColor]["hex"];
} else {
$displayedColor = $currentColor;
$resColor = BaseMappings::getColorByKey( $currentColor );
$displayedColor = $resColor ? $resColor[0] : $currentColor;
}
$mmlStyleColor = new MMLmstyle( "", [ "mathcolor" => $displayedColor ] );
$ret = $mmlStyleColor->encapsulateRaw( $currentNode->renderMML( $arguments, $state ) );

View file

@ -117,6 +117,24 @@ class MMLRenderTest extends MediaWikiUnitTestCase {
$this->assertStringContainsString( "movablelimits=\"true\"", $mathMLtexVC );
}
public function testColorGeneration1() {
$input = "\\color{Dandelion}{Dandelion}";
$mathMLtexVC = $this->generateMML( $input );
$this->assertStringContainsString( "#FDBC42", $mathMLtexVC );
}
public function testColorGeneration2() {
$input = "\\color{ForestGreen}{ForestGreen}";
$mathMLtexVC = $this->generateMML( $input );
$this->assertStringContainsString( "#009B55", $mathMLtexVC );
}
public function testColorGeneration3() {
$input = "\\color{Rhodamine}{Rhodamine}";
$mathMLtexVC = $this->generateMML( $input );
$this->assertStringContainsString( "#EF559F", $mathMLtexVC );
}
private function generateMML( $input, $chem = false ) {
$texVC = new TexVC();
$resultT = $texVC->check( $input, [