Merge "Fix spaces not rendering if within mtext"

This commit is contained in:
jenkins-bot 2023-03-21 18:46:03 +00:00 committed by Gerrit Code Review
commit 6e0181335f
2 changed files with 23 additions and 1 deletions

View file

@ -45,8 +45,20 @@ class Box extends TexNode {
public function renderMML( $arguments = [], $state = [] ) {
$mrow = new MMLmrow();
$mtext = new MMLmtext();
$arg = $this->getArg();
if ( strlen( $arg ) >= 1 ) {
// Replace trailing and leading spaces with special space sign
if ( substr( $arg, -1, 1 ) === " " ) {
$arg = rtrim( $arg, " " ) . " ";
}
if ( substr( $arg, 0, 1 ) == " " ) {
$arg = " " . ltrim( $arg, " " );
}
}
return $mrow->encapsulateRaw(
$mtext->encapsulateRaw( $this->getArg() )
$mtext->encapsulateRaw( $arg )
);
}

View file

@ -57,4 +57,14 @@ class BoxTest extends MediaWikiUnitTestCase {
$box = new Box( '\\hbox', 'a' );
$this->assertStringContainsString( '</mtext>', $box->renderMML(), 'Render MathML as text.' );
}
public function testTrailingSpaceBoxMML() {
$box = new Box( '\\hbox', 'a ' );
$this->assertStringContainsString( '&#xA0;', $box->renderMML(), 'Should have trailing rendered space' );
}
public function testPrecedingSpaceBoxMML() {
$box = new Box( '\\hbox', ' a' );
$this->assertStringContainsString( '&#xA0;', $box->renderMML(), 'Should have preceding rendered space' );
}
}