mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-28 01:10:09 +00:00
Merge "Fix style tag imbalance"
This commit is contained in:
commit
df0fbc7ebd
|
@ -157,7 +157,7 @@ class TexArray extends TexNode {
|
|||
public function renderMML( $arguments = [], $state = [] ) {
|
||||
// Everything here is for parsing displaystyle, probably refactored to TexVC grammar later
|
||||
$fullRenderedArray = "";
|
||||
$mmlStyle = null;
|
||||
$mmlStyles = [];
|
||||
$currentColor = null;
|
||||
|
||||
for ( $i = 0, $count = count( $this->args ); $i < $count; $i++ ) {
|
||||
|
@ -213,17 +213,23 @@ class TexArray extends TexNode {
|
|||
continue;
|
||||
}
|
||||
$styleArguments = $this->checkForStyleArgs( $current );
|
||||
// For cases with "displaystyle{someargs} otherargs"
|
||||
if ( $styleArguments ) {
|
||||
$mmlStyle = new MMLmstyle( "", $styleArguments );
|
||||
$state["styleargs"] = $styleArguments;
|
||||
$fullRenderedArray .= $mmlStyle->getStart();
|
||||
if ( $next instanceof Curly ) {
|
||||
// Wrap with style-tags when the next element is a Curly which determines start and end tag.
|
||||
$mmlStyle = new MMLmstyle( "", $styleArguments );
|
||||
$fullRenderedArray .= $mmlStyle->getStart();
|
||||
$fullRenderedArray .= $this->createMMLwithContext( $currentColor, $next, $state, $arguments );
|
||||
$fullRenderedArray .= $mmlStyle->getEnd();
|
||||
$mmlStyle = null;
|
||||
unset( $state["styleargs"] );
|
||||
$i++;
|
||||
} else {
|
||||
// Start the style indicator in cases like \textstyle abc
|
||||
$mmlStyle = new MMLmstyle( "", $styleArguments );
|
||||
$fullRenderedArray .= $mmlStyle->getStart();
|
||||
$mmlStyles[] = $mmlStyle->getEnd();
|
||||
|
||||
}
|
||||
} else {
|
||||
$fullRenderedArray .= $this->createMMLwithContext( $currentColor, $current, $state, $arguments );
|
||||
|
@ -239,8 +245,9 @@ class TexArray extends TexNode {
|
|||
unset( $state["deriv"] );
|
||||
}
|
||||
}
|
||||
if ( $mmlStyle ) {
|
||||
$fullRenderedArray .= $mmlStyle->getEnd();
|
||||
|
||||
foreach ( array_reverse( $mmlStyles ) as $mmlStyleEnd ) {
|
||||
$fullRenderedArray .= $mmlStyleEnd;
|
||||
}
|
||||
|
||||
return $fullRenderedArray;
|
||||
|
|
|
@ -150,6 +150,36 @@ class MMLRenderTest extends MediaWikiUnitTestCase {
|
|||
$this->assertStringContainsString( "#EF559F", $mathMLtexVC );
|
||||
}
|
||||
|
||||
public function testStyle1() {
|
||||
$input = "\\displaystyle \{U(\omega )\cdot \sigma _{H}(\omega )\} z";
|
||||
$mathMLtexVC = $this->generateMML( $input );
|
||||
$this->assertStringContainsString( "<mstyle displaystyle=\"true\" scriptlevel=\"0\">", $mathMLtexVC );
|
||||
$this->assertStringContainsString( "<mi>z</mi>", $mathMLtexVC );
|
||||
$this->assertStringContainsString( "</mstyle>", $mathMLtexVC, );
|
||||
}
|
||||
|
||||
public function testStyle2() {
|
||||
$input = "\\displaystyle abc \\textstyle def";
|
||||
$mathMLtexVC = $this->generateMML( $input );
|
||||
$this->assertStringContainsString( "<mstyle displaystyle=\"false\" scriptlevel=\"0\">", $mathMLtexVC );
|
||||
$this->assertStringContainsString( "</mstyle>", $mathMLtexVC, );
|
||||
}
|
||||
|
||||
public function testStyle3() {
|
||||
$input = "\\scriptstyle{abc} def \\textstyle ghi";
|
||||
$mathMLtexVC = $this->generateMML( $input );
|
||||
$this->assertStringContainsString( "<mstyle displaystyle=\"false\" scriptlevel=\"1\">", $mathMLtexVC );
|
||||
$this->assertStringContainsString( "</mstyle>", $mathMLtexVC, );
|
||||
}
|
||||
|
||||
public function testStyle4() {
|
||||
$input = "\\textstyle b > \\textstyle \\delta";
|
||||
$mathMLtexVC = $this->generateMML( $input );
|
||||
$count = 0;
|
||||
str_replace( "<mstyle displaystyle", "", $mathMLtexVC, $count );
|
||||
$this->assertEquals( 2, $count );
|
||||
}
|
||||
|
||||
private function generateMML( $input, $chem = false ) {
|
||||
$texVC = new TexVC();
|
||||
$resultT = $texVC->check( $input, [
|
||||
|
|
Loading…
Reference in a new issue