From 602043027d5117ae6b4fe645e07998e19937da89 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Sun, 13 Oct 2024 00:54:33 +0200 Subject: [PATCH] Implement basic column info parsing * For each letter l c or r that is found in the column spec the respective mtable alignment information is passed * if the align information is given externally the info will still be ignored Bug: T376838 Change-Id: I3113f933502df2109b066959e4d001736dbae6e6 --- src/WikiTexVC/MMLmappings/BaseParsing.php | 20 ++++++++++++++++++- .../WikiTexVC/MMLmappings/BaseParsingTest.php | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/WikiTexVC/MMLmappings/BaseParsing.php b/src/WikiTexVC/MMLmappings/BaseParsing.php index c5fcf4dd4..a96ec2efe 100644 --- a/src/WikiTexVC/MMLmappings/BaseParsing.php +++ b/src/WikiTexVC/MMLmappings/BaseParsing.php @@ -525,11 +525,28 @@ class BaseParsing { $mtr = new MMLmtr(); $mtd = new MMLmtd(); $tableArgs = [ "columnspacing" => "1em", "rowspacing" => "4pt", 'rowlines' => '' ]; + $columnInfo = trim( $node->getColumnSpecs()->render(), "{} \n\r\t\v\x00" ); if ( $align ) { $tableArgs['columnalign'] = $align; + } elseif ( $columnInfo ) { + $align = ''; + foreach ( str_split( $columnInfo ) as $chr ) { + switch ( $chr ) { + case 'r': + $align .= 'right '; + break; + case 'l': + $align .= 'left '; + break; + case 'c': + $align .= 'center '; + break; + } + } + $tableArgs['columnalign'] = $align; } $mencloseArgs = [ 'notation' => '' ]; - $columnInfo = $node->getColumnSpecs()->render(); + $lineNumber = 0; foreach ( $node as $row ) { $resInner .= $mtr->getStart(); @@ -576,6 +593,7 @@ class BaseParsing { // it seems this is creted when left and right is solely coming from columninfo $tableArgs = array_merge( $tableArgs, [ "columnlines" => "solid" ] ); } + } $mtable = new MMLmtable( "", $tableArgs ); if ( $cases || ( $open != null && $close != null ) ) { diff --git a/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php b/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php index 761477cf2..1abd0eb45 100644 --- a/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php +++ b/tests/phpunit/unit/WikiTexVC/MMLmappings/BaseParsingTest.php @@ -165,4 +165,13 @@ class BaseParsingTest extends TestCase { $this->assertStringContainsString( 'top bottom', $result ); } + public function testColumnSpecs() { + $matrix = ( new TexVC() )->parse( '\\begin{array}{lcr} +z & = & a \\\\ +f(x,y,z) & = & x + y + z +\\end{array}' )[0]; + $result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' ); + $this->assertStringContainsString( 'left center right ', $result ); + } + }