Skip to content

Commit

Permalink
clean up table parser handler
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Aug 13, 2010
1 parent d259f72 commit aa92c4c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions inc/parser/handler.php
Expand Up @@ -1175,15 +1175,15 @@ function process() {
$this->tableStart($call);
break;
case 'table_row':
$this->tableRowClose(array('tablerow_close',$call[1],$call[2]));
$this->tableRowClose($call);
$this->tableRowOpen(array('tablerow_open',$call[1],$call[2]));
break;
case 'tableheader':
case 'tablecell':
$this->tableCell($call);
break;
case 'table_end':
$this->tableRowClose(array('tablerow_close', array()));
$this->tableRowClose($call);
$this->tableEnd($call);
break;
default:
Expand Down Expand Up @@ -1221,7 +1221,7 @@ function tableRowClose($call) {
break;
}
}
$this->tableCalls[] = $call;
$this->tableCalls[] = array('tablerow_close', array(), $call[2]);

if ( $this->currentCols > $this->maxCols ) {
$this->maxCols = $this->currentCols;
Expand Down Expand Up @@ -1281,17 +1281,21 @@ function finalizeTable() {
// that contain colspans
foreach ( $this->tableCalls as $key => $call ) {

if ( $call[0] == 'tablerow_open' ) {
switch ($call[0]) {
case 'tablerow_open':

$lastRow++;
$lastCell = 0;
break;

} else if ( $call[0] == 'tablecell_open' || $call[0] == 'tableheader_open' ) {
case 'tablecell_open':
case 'tableheader_open':

$lastCell++;
$cellKey[$lastRow][$lastCell] = $key;
break;

} else if ( $call[0] == 'table_align' ) {
case 'table_align':

$prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));
$next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));
Expand All @@ -1315,8 +1319,9 @@ function finalizeTable() {

// Now convert the whitespace back to cdata
$this->tableCalls[$key][0] = 'cdata';
break;

} else if ( $call[0] == 'colspan' ) {
case 'colspan':

$this->tableCalls[$key-1][1][0] = false;

Expand All @@ -1336,8 +1341,9 @@ function finalizeTable() {
$toDelete[] = $key-1;
$toDelete[] = $key;
$toDelete[] = $key+1;
break;

} else if ( $call[0] == 'rowspan' ) {
case 'rowspan':

if ( $this->tableCalls[$key-1][0] == 'cdata' ) {
// ignore rowspan if previous call was cdata (text mixed with :::) we don't have to check next call as that wont match regex
Expand All @@ -1362,8 +1368,10 @@ function finalizeTable() {

$toDelete[] = $key-1;
$toDelete[] = $key;
$toDelete[] = $key+1;
$toDelete[] = $key+1;
}
break;

}
}

Expand Down

0 comments on commit aa92c4c

Please sign in to comment.