From cc0a214f560c7e5700b2b38161f7f1ec5e27a3c5 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Sun, 3 Nov 2024 08:58:50 +0100 Subject: [PATCH] Remove menclose in cancel rendering Chrome and similar browsers do not support the menclose tag. This change introduces a css polyfill suggested in https://github.com/w3c/mathml-core/issues/245#issuecomment-2410676518 but keeps the mencose rendering since FF does not support the polyfill https://bugzilla.mozilla.org/show_bug.cgi?id=1929800 Bug: T376829 Change-Id: I860e2f2f9bf9eef8eeba35b0999ec50175fdfc4b --- modules/ext.math.css | 28 +++++++++++++++++++ src/WikiTexVC/MMLmappings/BaseParsing.php | 12 +++++--- .../WikiTexVC/MMLmappings/BaseParsingTest.php | 4 ++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/modules/ext.math.css b/modules/ext.math.css index c18ab79e1..c60719495 100644 --- a/modules/ext.math.css +++ b/modules/ext.math.css @@ -79,3 +79,31 @@ mtd.mwe-math-matrix-left { mtd.mwe-math-matrix-right { border-right: 0.06em solid; } + +/* see https://github.com/w3c/mathml-core/issues/245#issuecomment-2410676518 */ +menclose.menclose { + position: relative; + padding: 0.5ex 0; +} + +mrow.menclose-updiagonalstrike { + display: inline-block; + position: absolute; + left: 0.5px; + bottom: 0; + width: 100%; + height: 100%; + background-color: currentcolor; + clip-path: polygon( 0.05em 100%, 0 calc( 100% - 0.05em ), calc( 100% - 0.05em ) 0, 100% 0.05em ); +} + +mrow.menclose-downdiagonalstrike { + display: inline-block; + position: absolute; + left: 0.5px; + bottom: 0; + width: 100%; + height: 100%; + background-color: currentcolor; + clip-path: polygon( 0 0, 0.05em 0, 100% 100%, calc( 100% - 0.05em ) 100% ); +} diff --git a/src/WikiTexVC/MMLmappings/BaseParsing.php b/src/WikiTexVC/MMLmappings/BaseParsing.php index 22bb92e72..eb8e91f67 100644 --- a/src/WikiTexVC/MMLmappings/BaseParsing.php +++ b/src/WikiTexVC/MMLmappings/BaseParsing.php @@ -159,10 +159,14 @@ class BaseParsing { return $mrow->encapsulateRaw( $node->getArg()->renderMML( $passedArgs ) ); } - public static function cancel( $node, $passedArgs, $operatorContent, $name, $notation = null, $smth2 = null ) { - $mrow = new MMLmrow(); - $menclose = new MMLmenclose( "", [ "notation" => $notation ] ); - return $mrow->encapsulateRaw( $menclose->encapsulateRaw( $node->getArg()->renderMML() ) ); + public static function cancel( Fun1 $node, $passedArgs, $operatorContent, $name, $notation = '' ): string { + $outer = new MMLmenclose( '', [ 'notation' => $notation, 'class' => 'menclose' ] ); + $bars = ''; + foreach ( explode( ' ', $notation ) as $element ) { + $bars .= ( new MMLmrow( '', [ 'class' => 'menclose-' . $element ] ) )->getEmpty(); + } + + return $outer->encapsulateRaw( $node->getArg()->renderMML() . $bars ); } public static function cancelTo( $node, $passedArgs, $operatorContent, $name, $notation = null ) { diff --git a/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php b/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php index 878fe29dd..47f36f11c 100644 --- a/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php +++ b/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php @@ -67,7 +67,9 @@ class BaseParsingTest extends TestCase { ( new Literal( 'a' ) ) ); $result = BaseParsing::cancel( $node, [], null, 'cancel', 'something' ); - $this->assertStringContainsString( 'a', + $this->assertStringContainsString( 'a', + $result ); + $this->assertStringContainsString( '', $result ); }