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(-) (limited to 'inc/parser/handler.php') 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