From f05a1cc5fcdb4c2b6ee3cbf499f980f800dbd105 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 17 Oct 2013 23:11:33 +0200 Subject: Wrap thead around 1st row, when 1st cell at 1st row is tableheader. Implements FS#1764 --- _test/tests/inc/parser/parser_table.test.php | 51 ++++++++++++++++++++++++++++ inc/parser/handler.php | 19 +++++++++-- inc/parser/renderer.php | 4 +++ inc/parser/xhtml.php | 8 +++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/_test/tests/inc/parser/parser_table.test.php b/_test/tests/inc/parser/parser_table.test.php index 542a307b8..5258afe3d 100644 --- a/_test/tests/inc/parser/parser_table.test.php +++ b/_test/tests/inc/parser/parser_table.test.php @@ -125,6 +125,7 @@ def'); array('cdata',array("\n\nabc")), array('p_close',array()), array('table_open',array(3, 1, 6)), + array('tablethead_open',array()), array('tablerow_open',array()), array('tableheader_open',array(1,NULL,1)), array('cdata',array(' X ')), @@ -136,6 +137,7 @@ def'); array('cdata',array(' Z ')), array('tableheader_close',array()), array('tablerow_close',array()), + array('tablethead_close',array()), array('table_close',array(19)), array('p_open',array()), array('cdata',array('def')), @@ -146,6 +148,55 @@ def'); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } + + function testTableHeadersMultilines() { + $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->parse(' +abc +^ X | Y ^ Z | +| A | B | C | +def'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n\nabc")), + array('p_close',array()), + array('table_open',array(3, 2, 6)), + array('tablethead_open',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X ')), + array('tableheader_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' Y ')), + array('tablecell_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablethead_close',array()), + array('tablerow_open',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' A ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' B ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' C ')), + array('tablecell_close',array()), + array('tablerow_close',array()), + array('table_close',array(33)), + array('p_open',array()), + array('cdata',array('def')), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + + } function testCellAlignment() { $this->P->addMode('table',new Doku_Parser_Mode_Table()); diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 1de981b48..55f344994 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1278,6 +1278,7 @@ class Doku_Handler_Table { $lastRow = 0; $lastCell = 0; + $isThead = false; $cellKey = array(); $toDelete = array(); @@ -1292,6 +1293,14 @@ class Doku_Handler_Table { $lastRow++; $lastCell = 0; + + if($lastRow === 1 && $this->tableCalls[$key+1][0] == 'tableheader_open') { + $isThead = true; + + array_splice($this->tableCalls, $key, 0, array( + array('tablethead_open', array(), $call[2]))); + $key += 1; + } break; case 'tablecell_open': @@ -1396,6 +1405,12 @@ class Doku_Handler_Table { $key += 3; } + if($isThead) { + array_splice($this->tableCalls, $key+1, 0, array( + array('tablethead_close', array(), $call[2]))); + + $isThead = false; + } break; } @@ -1437,7 +1452,7 @@ class Doku_Handler_Block { var $blockOpen = array( 'header', 'listu_open','listo_open','listitem_open','listcontent_open', - 'table_open','tablerow_open','tablecell_open','tableheader_open', + 'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open', 'quote_open', 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', @@ -1447,7 +1462,7 @@ class Doku_Handler_Block { var $blockClose = array( 'header', 'listu_close','listo_close','listitem_close','listcontent_close', - 'table_close','tablerow_close','tablecell_close','tableheader_close', + 'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close', 'quote_close', 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index c697e990c..ee0b2344d 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -245,6 +245,10 @@ class Doku_Renderer extends DokuWiki_Plugin { function table_close($pos = null){} + function tablethead_open(){} + + function tablethead_close(){} + function tablerow_open(){} function tablerow_close(){} diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index fd02c0ce0..e9f2cc037 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -946,6 +946,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { } } + function tablethead_open(){ + $this->doc .= DOKU_TAB . '' . DOKU_LF; + } + + function tablethead_close(){ + $this->doc .= DOKU_TAB . '' . DOKU_LF; + } + function tablerow_open(){ // initialize the cell counter used for classes $this->_counter['cell_counter'] = 0; -- cgit v1.2.3 From 9060b8b02222ada7d08f4f6b77b4dd1e125fe5a2 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 18 Oct 2013 14:34:55 +0100 Subject: add to top rows of tables when all cells are --- inc/parser/handler.php | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 55f344994..196cafc57 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1149,6 +1149,8 @@ class Doku_Handler_Table { var $currentCols = 0; var $firstCell = false; var $lastCellType = 'tablecell'; + var $inTableHead = true; + var $countTableHeadRows = 0; function Doku_Handler_Table(& $CallWriter) { $this->CallWriter = & $CallWriter; @@ -1219,6 +1221,9 @@ class Doku_Handler_Table { } function tableRowClose($call) { + if ($this->inTableHead) { + $this->countTableHeadRows++; + } // Strip off final cell opening and anything after it while ( $discard = array_pop($this->tableCalls ) ) { @@ -1234,6 +1239,9 @@ class Doku_Handler_Table { } function tableCell($call) { + if ($call[0] != 'tableheader') { + $this->inTableHead = false; + } if ( !$this->firstCell ) { // Increase the span @@ -1278,7 +1286,6 @@ class Doku_Handler_Table { $lastRow = 0; $lastCell = 0; - $isThead = false; $cellKey = array(); $toDelete = array(); @@ -1289,18 +1296,18 @@ class Doku_Handler_Table { $call = $this->tableCalls[$key]; switch ($call[0]) { + case 'table_open' : + if($this->countTableHeadRows) { + array_splice($this->tableCalls, $key+1, 0, array( + array('tablethead_open', array(), $call[2])) + ); + } + break; + case 'tablerow_open': $lastRow++; $lastCell = 0; - - if($lastRow === 1 && $this->tableCalls[$key+1][0] == 'tableheader_open') { - $isThead = true; - - array_splice($this->tableCalls, $key, 0, array( - array('tablethead_open', array(), $call[2]))); - $key += 1; - } break; case 'tablecell_open': @@ -1366,15 +1373,19 @@ class Doku_Handler_Table { } else { $spanning_cell = null; - for($i = $lastRow-1; $i > 0; $i--) { - if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) { + // can't cross thead/tbody boundary + if (!$this->countTableHeadRows || ($lastRow-1 != $this->countTableHeadRows)) { + for($i = $lastRow-1; $i > 0; $i--) { - if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) { - $spanning_cell = $i; - break; - } + if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) { + if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) { + $spanning_cell = $i; + break; + } + + } } } if (is_null($spanning_cell)) { @@ -1405,11 +1416,9 @@ class Doku_Handler_Table { $key += 3; } - if($isThead) { + if($this->countTableHeadRows == $lastRow) { array_splice($this->tableCalls, $key+1, 0, array( array('tablethead_close', array(), $call[2]))); - - $isThead = false; } break; -- cgit v1.2.3 From 688ce8d8ab7995792e25b09b8481dc04c8363aab Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 18 Oct 2013 14:38:10 +0100 Subject: update tests for use with changes --- _test/tests/inc/parser/parser_table.test.php | 195 +++++++++++++++++++++++++-- 1 file changed, 183 insertions(+), 12 deletions(-) diff --git a/_test/tests/inc/parser/parser_table.test.php b/_test/tests/inc/parser/parser_table.test.php index 5258afe3d..6961d568c 100644 --- a/_test/tests/inc/parser/parser_table.test.php +++ b/_test/tests/inc/parser/parser_table.test.php @@ -125,7 +125,6 @@ def'); array('cdata',array("\n\nabc")), array('p_close',array()), array('table_open',array(3, 1, 6)), - array('tablethead_open',array()), array('tablerow_open',array()), array('tableheader_open',array(1,NULL,1)), array('cdata',array(' X ')), @@ -137,7 +136,6 @@ def'); array('cdata',array(' Z ')), array('tableheader_close',array()), array('tablerow_close',array()), - array('tablethead_close',array()), array('table_close',array(19)), array('p_open',array()), array('cdata',array('def')), @@ -145,16 +143,15 @@ def'); array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } - function testTableHeadersMultilines() { + function testTableHead() { $this->P->addMode('table',new Doku_Parser_Mode_Table()); $this->P->parse(' abc -^ X | Y ^ Z | -| A | B | C | +^ X ^ Y ^ Z ^ def'); $calls = array ( @@ -162,20 +159,70 @@ def'); array('p_open',array()), array('cdata',array("\n\nabc")), array('p_close',array()), - array('table_open',array(3, 2, 6)), + array('table_open',array(3, 1, 6)), array('tablethead_open',array()), array('tablerow_open',array()), array('tableheader_open',array(1,NULL,1)), array('cdata',array(' X ')), array('tableheader_close',array()), - array('tablecell_open',array(1,NULL,1)), + array('tableheader_open',array(1,NULL,1)), array('cdata',array(' Y ')), - array('tablecell_close',array()), + array('tableheader_close',array()), array('tableheader_open',array(1,NULL,1)), array('cdata',array(' Z ')), array('tableheader_close',array()), array('tablerow_close',array()), array('tablethead_close',array()), + array('table_close',array(19)), + array('p_open',array()), + array('cdata',array('def')), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); + + } + + function testTableHeadMultiline() { + $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->parse(' +abc +^ X1 ^ Y1 ^ Z1 ^ +^ X2 ^ Y2 ^ Z2 ^ +| A | B | C | +def'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n\nabc")), + array('p_close',array()), + array('table_open',array(3, 3, 6)), + array('tablethead_open',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X1 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Y1 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z1 ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X2 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Y2 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z2 ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablethead_close',array()), array('tablerow_open',array()), array('tablecell_open',array(1,NULL,1)), array('cdata',array(' A ')), @@ -187,14 +234,14 @@ def'); array('cdata',array(' C ')), array('tablecell_close',array()), array('tablerow_close',array()), - array('table_close',array(33)), + array('table_close',array(53)), array('p_open',array()), array('cdata',array('def')), array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } @@ -380,6 +427,131 @@ def'); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } + function testRowSpanTableHead() { + $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->parse(' +abc +^ X1 ^ Y1 ^ Z1 ^ +^ X2 ^ ::: ^ Z2 ^ +| A3 | B3 | C3 | +def'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n\nabc")), + array('p_close',array()), + array('table_open',array(3, 3, 6)), + array('tablethead_open',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X1 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,2)), + array('cdata',array(' Y1 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z1 ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X2 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z2 ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablethead_close',array()), + array('tablerow_open',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' A3 ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' B3 ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' C3 ')), + array('tablecell_close',array()), + array('tablerow_close',array()), + array('table_close',array(57)), + array('p_open',array()), + array('cdata',array('def')), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); + + } + + function testRowSpanAcrossTableHeadBoundary() { + $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->parse(' +abc +^ X1 ^ Y1 ^ Z1 ^ +^ X2 ^ ::: ^ Z2 ^ +| A3 | ::: | C3 | +| A4 | ::: | C4 | +def'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n\nabc")), + array('p_close',array()), + array('table_open',array(3, 4, 6)), + array('tablethead_open',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X1 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,2)), + array('cdata',array(' Y1 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z1 ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X2 ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z2 ')), + array('tableheader_close',array()), + array('tablerow_close',array()), + array('tablethead_close',array()), + array('tablerow_open',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' A3 ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,2)), + array('cdata',array('')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' C3 ')), + array('tablecell_close',array()), + array('tablerow_close',array()), + array('tablerow_open',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' A4 ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' C4 ')), + array('tablecell_close',array()), + array('tablerow_close',array()), + array('table_close',array(76)), + array('p_open',array()), + array('cdata',array('def')), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); + + } + function testCellAlignmentFormatting() { $this->P->addMode('table',new Doku_Parser_Mode_Table()); $this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong')); @@ -678,4 +850,3 @@ def'); $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); } } - -- cgit v1.2.3 From e0328e30d24321e319e2733192bf829b9000c5eb Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 18 Oct 2013 14:42:46 +0100 Subject: swap order ot test parameters to match expected,actual as per documentation & test output --- _test/tests/inc/parser/parser_table.test.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/_test/tests/inc/parser/parser_table.test.php b/_test/tests/inc/parser/parser_table.test.php index 6961d568c..d4596bc8a 100644 --- a/_test/tests/inc/parser/parser_table.test.php +++ b/_test/tests/inc/parser/parser_table.test.php @@ -44,7 +44,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testTableWinEOL() { @@ -84,7 +84,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testEmptyTable() { @@ -109,7 +109,7 @@ def'); array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testTableHeaders() { @@ -276,7 +276,7 @@ def'); array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testCellSpan() { @@ -318,7 +318,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testCellRowSpan() { @@ -366,7 +366,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testCellRowSpanFirstRow() { @@ -424,7 +424,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testRowSpanTableHead() { @@ -588,7 +588,7 @@ def'); array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } @@ -634,7 +634,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } // This is really a failing test - formatting able to spread across cols @@ -689,7 +689,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } // This is really a failing test - unformatted able to spread across cols @@ -740,7 +740,7 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } function testTableLinebreak() { @@ -788,7 +788,7 @@ def'); array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } // This is really a failing test - footnote able to spread across cols @@ -847,6 +847,6 @@ def'); array('p_close',array()), array('document_end',array()), ); - $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls); + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); } } -- cgit v1.2.3 From cef031c123914a2d88f125a8363c0917011e8ed0 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 13 Mar 2014 17:52:03 +0000 Subject: implement rules for when the top rows of a table qualify for a THEAD element 1. TD < 2 in a row 2. TD <= 50% of total cells 3. Not all table rows can be THEAD rows --- inc/parser/handler.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/inc/parser/handler.php b/inc/parser/handler.php index c4104dac9..d8382e7fc 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1150,6 +1150,7 @@ class Doku_Handler_Table { var $firstCell = false; var $lastCellType = 'tablecell'; var $inTableHead = true; + var $currentRow = array('tableheader' => 0, 'tablecell' => 0); var $countTableHeadRows = 0; function Doku_Handler_Table(& $CallWriter) { @@ -1218,10 +1219,13 @@ class Doku_Handler_Table { $this->firstCell = true; $this->lastCellType = 'tablecell'; $this->maxRows++; + if ($this->inTableHead) { + $this->currentRow = array('tablecell' => 0, 'tableheader' => 0); + } } function tableRowClose($call) { - if ($this->inTableHead) { + if ($this->inTableHead && ($this->inTableHead = $this->isTableHeadRow())) { $this->countTableHeadRows++; } // Strip off final cell opening and anything after it @@ -1230,6 +1234,9 @@ class Doku_Handler_Table { if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') { break; } + if (!empty($this->currentRow[$discard[0]])) { + $this->currentRow[$discard[0]]--; + } } $this->tableCalls[] = array('tablerow_close', array(), $call[2]); @@ -1238,9 +1245,19 @@ class Doku_Handler_Table { } } + function isTableHeadRow() { + $td = $this->currentRow['tablecell']; + $th = $this->currentRow['tableheader']; + + if (!$th || $td > 2) return false; + if (2*$td > $th) return false; + + return true; + } + function tableCell($call) { - if ($call[0] != 'tableheader') { - $this->inTableHead = false; + if ($this->inTableHead) { + $this->currentRow[$call[0]]++; } if ( !$this->firstCell ) { @@ -1289,6 +1306,13 @@ class Doku_Handler_Table { $cellKey = array(); $toDelete = array(); + // if still in tableheader, then there can be no table header + // as all rows can't be within + if ($this->inTableHead) { + $this->inTableHead = false; + $this->countTableHeadRows = 0; + } + // Look for the colspan elements and increment the colspan on the // previous non-empty opening cell. Once done, delete all the cells // that contain colspans -- cgit v1.2.3 From c2a1d01e2e905ab3d7fa3009aeb140fcefc32f9e Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 16 Mar 2014 20:26:44 +0000 Subject: update unittests for THEAD rules --- _test/tests/inc/parser/parser_table.test.php | 49 +++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/_test/tests/inc/parser/parser_table.test.php b/_test/tests/inc/parser/parser_table.test.php index 3e9651d14..a9b4e284c 100644 --- a/_test/tests/inc/parser/parser_table.test.php +++ b/_test/tests/inc/parser/parser_table.test.php @@ -152,6 +152,7 @@ def'); $this->P->parse(' abc ^ X ^ Y ^ Z ^ +| x | y | z | def'); $calls = array ( @@ -159,7 +160,7 @@ def'); array('p_open',array()), array('cdata',array("\n\nabc")), array('p_close',array()), - array('table_open',array(3, 1, 6)), + array('table_open',array(3, 2, 6)), array('tablethead_open',array()), array('tablerow_open',array()), array('tableheader_open',array(1,NULL,1)), @@ -173,6 +174,52 @@ def'); array('tableheader_close',array()), array('tablerow_close',array()), array('tablethead_close',array()), + array('tablerow_open',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' x ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' y ')), + array('tablecell_close',array()), + array('tablecell_open',array(1,NULL,1)), + array('cdata',array(' z ')), + array('tablecell_close',array()), + array('tablerow_close',array()), + array('table_close',array(33)), + array('p_open',array()), + array('cdata',array('def')), + array('p_close',array()), + array('document_end',array()), + ); + + $this->assertEquals($calls,array_map('stripbyteindex',$this->H->calls)); + + } + + function testTableHeadOneRowTable() { + $this->P->addMode('table',new Doku_Parser_Mode_Table()); + $this->P->parse(' +abc +^ X ^ Y ^ Z ^ +def'); + + $calls = array ( + array('document_start',array()), + array('p_open',array()), + array('cdata',array("\n\nabc")), + array('p_close',array()), + array('table_open',array(3, 1, 6)), + array('tablerow_open',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' X ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Y ')), + array('tableheader_close',array()), + array('tableheader_open',array(1,NULL,1)), + array('cdata',array(' Z ')), + array('tableheader_close',array()), + array('tablerow_close',array()), array('table_close',array(19)), array('p_open',array()), array('cdata',array('def')), -- cgit v1.2.3