mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-23 15:16:56 +00:00
Merge "Squash literals in operatornames"
This commit is contained in:
commit
188d13ca64
|
@ -361,7 +361,7 @@ class BaseParsing {
|
|||
$mmlNot = MMLParsingUtil::createNot();
|
||||
}
|
||||
$passedArgs = array_merge( $passedArgs, [ Tag::CLASSTAG => TexClass::OP, "mathvariant" => Variants::NORMAL ] );
|
||||
return $mmlNot . $node->getArg()->renderMML( $passedArgs ) . $applyFct;
|
||||
return $mmlNot . $node->getArg()->renderMML( $passedArgs, [ 'squashLiterals' => true ] ) . $applyFct;
|
||||
}
|
||||
|
||||
public static function lap( $node, $passedArgs, $operatorContent, $name ) {
|
||||
|
|
|
@ -193,12 +193,32 @@ class TexArray extends TexNode implements \ArrayAccess, \IteratorAggregate {
|
|||
return [ $hasNamedFct, $hasValidParameters ];
|
||||
}
|
||||
|
||||
private function squashLiterals() {
|
||||
$tmp = '';
|
||||
foreach ( $this->args as $arg ) {
|
||||
if ( !( $arg instanceof Literal ) ) {
|
||||
return;
|
||||
}
|
||||
// Don't squash if there is a macro in the literal
|
||||
if ( preg_match( "/[\\\\]/", $arg->getArg() ) ) {
|
||||
return;
|
||||
}
|
||||
$tmp .= $arg->getArg();
|
||||
}
|
||||
$this->args = [ new Literal( $tmp ) ];
|
||||
$this->curly = false;
|
||||
}
|
||||
|
||||
public function renderMML( $arguments = [], $state = [] ) {
|
||||
// Everything here is for parsing displaystyle, probably refactored to WikiTexVC grammar later
|
||||
$fullRenderedArray = "";
|
||||
$mmlStyles = [];
|
||||
$currentColor = null;
|
||||
|
||||
if ( array_key_exists( 'squashLiterals', $state ) ) {
|
||||
$this->squashLiterals();
|
||||
}
|
||||
|
||||
for ( $i = 0, $count = count( $this->args ); $i < $count; $i++ ) {
|
||||
$current = $this->args[$i];
|
||||
if ( isset( $this->args[$i + 1] ) ) {
|
||||
|
|
|
@ -120,4 +120,16 @@ class TexArrayTest extends MediaWikiUnitTestCase {
|
|||
$ta = new TexArray();
|
||||
$ta[0] = 'a';
|
||||
}
|
||||
|
||||
public function testSquashLiterals() {
|
||||
$ta = new TexArray( new Literal( 'a' ), new Literal( 'b' ) );
|
||||
$res = $ta->renderMML( [], [ 'squashLiterals' => true ] );
|
||||
$this->assertEquals( '<mi>ab</mi>', $res );
|
||||
}
|
||||
|
||||
public function testSquashLiteralsMacro() {
|
||||
$ta = new TexArray( new Literal( 'a' ), new Literal( '\gamma' ) );
|
||||
$res = $ta->renderMML( [], [ 'squashLiterals' => true ] );
|
||||
$this->assertEquals( '<mi>a</mi><mi>γ</mi>', $res );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue