From 5f9ca781d15092251a58a0723cce81c48bff7f59 Mon Sep 17 00:00:00 2001 From: Stegmujo Date: Thu, 16 Mar 2023 14:47:26 +0000 Subject: [PATCH] Fix spaces not rendering if within mtext * MMLFullCoverageTest case: 260 Bug: T327391 Change-Id: Ifd858216b646efd53c401ac9bcddfc7fb1c1a933 --- src/TexVC/Nodes/Box.php | 14 +++++++++++++- tests/phpunit/unit/TexVC/Nodes/BoxTest.php | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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' ); + } }