Merge "Don't stretch delimiters and operators when used as literals"

This commit is contained in:
jenkins-bot 2024-11-14 09:11:45 +00:00 committed by Gerrit Code Review
commit 0bfd22b57b
4 changed files with 21 additions and 6 deletions

View file

@ -91,7 +91,7 @@ class BaseMethods {
return $this->parseOperatorDict( $node, $passedArgs, $operatorContent, $input, false );
}
// Atm just do simple parsing for elements in operator dictionary
$mmlMo = new MMLmo();
$mmlMo = new MMLmo( '', $passedArgs );
return $mmlMo->encapsulateRaw( $input );
}
}

View file

@ -92,7 +92,10 @@ class Literal extends TexNode {
// Sieve for Operators
$bm = new BaseMethods();
$ret = $bm->checkAndParseOperator( $inputP, $this, $arguments, $operatorContent, $state, false );
$noStretchArgs = $arguments;
// Delimiters and operators should not be stretchy by default when used as literals
$noStretchArgs['stretchy'] ??= 'false';
$ret = $bm->checkAndParseOperator( $inputP, $this, $noStretchArgs, $operatorContent, $state, false );
if ( $ret ) {
return $ret;
}
@ -109,7 +112,7 @@ class Literal extends TexNode {
return $ret;
}
// Sieve for Delimiters
$ret = $bm->checkAndParseDelimiter( $input, $this, $arguments, $operatorContent );
$ret = $bm->checkAndParseDelimiter( $input, $this, $noStretchArgs, $operatorContent );
if ( $ret ) {
return $ret;
}

View file

@ -56,7 +56,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
$mml = $res['input']->renderMML();
$this->assertStringContainsString( '<mi', $mml );
$this->assertStringContainsString( $result . '</mi>', $mml );
$this->assertStringContainsString( '<mo>&#x223C;</mo>', $mml );
$this->assertStringContainsString( '&#x223C;</mo>', $mml );
}
public function testHarpoonsLeftRight() {
@ -77,7 +77,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
$warnings = [];
$res = $texVC->check( $input, $options, $warnings, true );
$mml = $res['input']->renderMML();
$this->assertStringContainsString( '<mo>&#x2212;</mo>', $mml );
$this->assertStringContainsString( '&#x2212;</mo>', $mml );
$this->assertStringContainsString( '&#x21C0;', $mml );
$this->assertStringContainsString( '<mpadded height="0" depth="0">', $mml );
$this->assertStringContainsString( '<mspace ', $mml );
@ -212,7 +212,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase {
$warnings = [];
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ],
$warnings, true );
$this->assertStringContainsString( '<mpadded width="0"><mo>&#x2212;</mo></mpadded>',
$this->assertStringContainsString( '&#x2212;</mo></mpadded>',
$checkRes["input"]->renderMML() );
}

View file

@ -106,4 +106,16 @@ class LiteralTest extends MediaWikiUnitTestCase {
'colon should render as special operator.' );
}
public function testRangle() {
$n = new Literal( '\\rangle' );
$this->assertStringContainsString( 'stretchy="false"', $n->renderMML(),
'colon should render as special operator.' );
}
public function testVert() {
$n = new Literal( '|' );
$this->assertStringContainsString( 'stretchy="false"', $n->renderMML(),
'| should render as special operator.' );
}
}