diff --git a/src/TexVC/Nodes/Box.php b/src/TexVC/Nodes/Box.php index 3c4c95a82..01e5f673c 100644 --- a/src/TexVC/Nodes/Box.php +++ b/src/TexVC/Nodes/Box.php @@ -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 ) ); } diff --git a/tests/phpunit/unit/TexVC/Nodes/BoxTest.php b/tests/phpunit/unit/TexVC/Nodes/BoxTest.php index 152b09c1c..9a7f1beb6 100644 --- a/tests/phpunit/unit/TexVC/Nodes/BoxTest.php +++ b/tests/phpunit/unit/TexVC/Nodes/BoxTest.php @@ -57,4 +57,14 @@ class BoxTest extends MediaWikiUnitTestCase { $box = new Box( '\\hbox', 'a' ); $this->assertStringContainsString( '', $box->renderMML(), 'Render MathML as text.' ); } + + public function testTrailingSpaceBoxMML() { + $box = new Box( '\\hbox', 'a ' ); + $this->assertStringContainsString( ' ', $box->renderMML(), 'Should have trailing rendered space' ); + } + + public function testPrecedingSpaceBoxMML() { + $box = new Box( '\\hbox', ' a' ); + $this->assertStringContainsString( ' ', $box->renderMML(), 'Should have preceding rendered space' ); + } }