From 758f9c987a7a69d8ac950d2ed1c2b5417f343be4 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Sun, 10 Nov 2024 16:45:23 +0100 Subject: [PATCH] Overwrite spacing for divide This overwrite should be removed once this is the default in all browsers. Bug: T375337 Change-Id: I5ab133f0368ed6eef94b0a87281bb9129fca406c --- src/WikiTexVC/MMLmappings/BaseMethods.php | 3 +++ src/WikiTexVC/MMLmappings/OperatorDictionary.php | 2 +- tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/WikiTexVC/MMLmappings/BaseMethods.php b/src/WikiTexVC/MMLmappings/BaseMethods.php index 8bf289bb7..0eafb6ecb 100644 --- a/src/WikiTexVC/MMLmappings/BaseMethods.php +++ b/src/WikiTexVC/MMLmappings/BaseMethods.php @@ -131,6 +131,9 @@ class BaseMethods { // see: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/961213 $mspace = new MMLmspace( "", [ "width" => "0.5em" ] ); return $mspace->getEmpty(); + case '/': + $mmlMo = new MMLmo( '', [ 'lspace' => '0', 'rspace' => '0' ] ); + return $mmlMo->encapsulateRaw( $input ); } return $input; } diff --git a/src/WikiTexVC/MMLmappings/OperatorDictionary.php b/src/WikiTexVC/MMLmappings/OperatorDictionary.php index 63d416a6c..9597bd3c7 100644 --- a/src/WikiTexVC/MMLmappings/OperatorDictionary.php +++ b/src/WikiTexVC/MMLmappings/OperatorDictionary.php @@ -35,7 +35,7 @@ class OperatorDictionary { '->' => [ " exports.MO.BIN5" ], '.' => [ " [0, 3], MmlNode_js_1.TEXCLASS.PUNCT\"], { separator=> [ true }]" ], ':' => [ " [1, 2], MmlNode_js_1.TEXCLASS.REL\"], null]" ], - '/' => [ " exports.MO.ORD11" ], + '/' => [ " exports.MO.ORD11", true ], '//' => [ " OPDEF(1\"], 1)" ], '/=' => [ " exports.MO.BIN4" ], '=>' => [ " [1, 2], MmlNode_js_1.TEXCLASS.REL\"], null]" ], diff --git a/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php b/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php index 25b9e77ac..9dd963f1a 100644 --- a/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php +++ b/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php @@ -124,4 +124,13 @@ class LiteralTest extends MediaWikiUnitTestCase { 'exclamation mark should render as special operator.' ); } + public function testDivide() { + $n = new Literal( '/' ); + $real = $n->renderMML(); + $this->assertStringContainsString( '/', $real, + 'divide should render as special operator.' ); + $this->assertStringContainsString( 'lspace="0" rspace="0"', $real, + 'divide should have no spacing.' ); + } + }