diff options
author | hakan.sandell <hakan.sandell@mydata.se> | 2009-11-03 17:10:02 +0100 |
---|---|---|
committer | hakan.sandell <hakan.sandell@mydata.se> | 2009-11-03 17:10:02 +0100 |
commit | 25b97867c7d50ea2cbce4db0662c278b135db5a6 (patch) | |
tree | 118c91d7ec12538d544528b4dbd7ddd2c71cbad2 /inc/parser | |
parent | 1f8eb24f4e8a49f1d2205b797b0ab46b82105b5f (diff) | |
download | rpg-25b97867c7d50ea2cbce4db0662c278b135db5a6.tar.gz rpg-25b97867c7d50ea2cbce4db0662c278b135db5a6.tar.bz2 |
rowspan with ::: implemented in parser/handler
darcs-hash:20091103161002-9a5f4-2114938a7e62a924b9fe424b63584a4747286563.gz
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/handler.php | 63 | ||||
-rw-r--r-- | inc/parser/metadata.php | 4 | ||||
-rw-r--r-- | inc/parser/parser.php | 2 | ||||
-rw-r--r-- | inc/parser/renderer.php | 4 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 10 |
5 files changed, 54 insertions, 29 deletions
diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 43c9489fe..8ba3d1be1 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -584,7 +584,6 @@ class Doku_Handler { $this->CallWriter = & $ReWriter; $this->_addCall('table_start', array(), $pos); - //$this->_addCall('table_row', array(), $pos); if ( trim($match) == '^' ) { $this->_addCall('tableheader', array(), $pos); } else { @@ -608,6 +607,8 @@ class Doku_Handler { case DOKU_LEXER_MATCHED: if ( $match == ' ' ){ $this->_addCall('cdata', array($match), $pos); + } else if ( preg_match('/:::/',$match) ) { + $this->_addCall('rowspan', array($match), $pos); } else if ( preg_match('/\t+/',$match) ) { $this->_addCall('table_align', array($match), $pos); } else if ( preg_match('/ {2,}/',$match) ) { @@ -1236,19 +1237,6 @@ class Doku_Handler_Table { while ( $discard = array_pop($this->tableCalls ) ) { if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') { - - // Its a spanning element - put it back and close it - if ( $discard[1][0] > 1 ) { - - $this->tableCalls[] = $discard; - if ( strstr($discard[0],'cell') ) { - $name = 'tablecell'; - } else { - $name = 'tableheader'; - } - $this->tableCalls[] = array($name.'_close',array(),$call[2]); - } - break; } } @@ -1272,12 +1260,12 @@ class Doku_Handler_Table { } $this->tableCalls[] = array($this->lastCellType.'_close',array(),$call[2]); - $this->tableCalls[] = array($call[0].'_open',array(1,NULL),$call[2]); + $this->tableCalls[] = array($call[0].'_open',array(1,NULL,1),$call[2]); $this->lastCellType = $call[0]; } else { - $this->tableCalls[] = array($call[0].'_open',array(1,NULL),$call[2]); + $this->tableCalls[] = array($call[0].'_open',array(1,NULL,1),$call[2]); $this->lastCellType = $call[0]; $this->firstCell = false; @@ -1303,6 +1291,7 @@ class Doku_Handler_Table { $lastRow = 0; $lastCell = 0; + $cellKey = array(); $toDelete = array(); // Look for the colspan elements and increment the colspan on the @@ -1312,11 +1301,13 @@ class Doku_Handler_Table { if ( $call[0] == 'tablerow_open' ) { - $lastRow = $key; + $lastRow++; + $lastCell = 0; } else if ( $call[0] == 'tablecell_open' || $call[0] == 'tableheader_open' ) { - $lastCell = $key; + $lastCell++; + $cellKey[$lastRow][$lastCell] = $key; } else if ( $call[0] == 'table_align' ) { @@ -1332,10 +1323,10 @@ class Doku_Handler_Table { // If the next element is the close of an element, align either center or left } elseif ( $next) { - if ( $this->tableCalls[$lastCell][1][1] == 'right' ) { - $this->tableCalls[$lastCell][1][1] = 'center'; + if ( $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] == 'right' ) { + $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'center'; } else { - $this->tableCalls[$lastCell][1][1] = 'left'; + $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'left'; } } @@ -1347,7 +1338,7 @@ class Doku_Handler_Table { $this->tableCalls[$key-1][1][0] = false; - for($i = $key-2; $i > $lastRow; $i--) { + for($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) { if ( $this->tableCalls[$i][0] == 'tablecell_open' || $this->tableCalls[$i][0] == 'tableheader_open' ) { @@ -1363,6 +1354,34 @@ class Doku_Handler_Table { $toDelete[] = $key-1; $toDelete[] = $key; $toDelete[] = $key+1; + + } else if ( $call[0] == '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 + $this->tableCalls[$key][0] = 'cdata'; + + } else { + + $this->tableCalls[$key-1][1][2] = false; + + for($i = $lastRow-1; $i > 0; $i--) { + + if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) { + + if ( false !== $this->tableCalls[$cellKey[$i][$lastCell]][1][2] ) { + $this->tableCalls[$cellKey[$i][$lastCell]][1][2]++; + break; + } + + + } + } + + $toDelete[] = $key-1; + $toDelete[] = $key; + $toDelete[] = $key+1; + } } } diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 88d531af1..8aa00b4f5 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -397,10 +397,10 @@ class Doku_Renderer_metadata extends Doku_Renderer { function tablerow_open(){} function tablerow_close(){} - function tableheader_open($colspan = 1, $align = NULL){} + function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} function tableheader_close(){} - function tablecell_open($colspan = 1, $align = NULL){} + function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} function tablecell_close(){} //---------------------------------------------------------- diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 77909a436..a78b08a29 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -452,7 +452,7 @@ class Doku_Parser_Mode_table extends Doku_Parser_Mode { function postConnect() { $this->Lexer->addPattern('\n\^','table'); $this->Lexer->addPattern('\n\|','table'); - #$this->Lexer->addPattern(' {2,}','table'); + $this->Lexer->addPattern('[\t ]*:::[\t ]*(?=[\|\^])','table'); $this->Lexer->addPattern('[\t ]+','table'); $this->Lexer->addPattern('\^','table'); $this->Lexer->addPattern('\|','table'); diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 94aa5c67b..a0687f53d 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -239,11 +239,11 @@ class Doku_Renderer extends DokuWiki_Plugin { function tablerow_close(){} - function tableheader_open($colspan = 1, $align = NULL){} + function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} function tableheader_close(){} - function tablecell_open($colspan = 1, $align = NULL){} + function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} function tablecell_close(){} diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index e68df6709..d2669a39c 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -948,7 +948,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; } - function tableheader_open($colspan = 1, $align = NULL){ + function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){ $class = 'class="col' . $this->_counter['cell_counter']++; if ( !is_null($align) ) { $class .= ' '.$align.'align'; @@ -959,6 +959,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->_counter['cell_counter'] += $colspan-1; $this->doc .= ' colspan="'.$colspan.'"'; } + if ( $rowspan > 1 ) { + $this->doc .= ' rowspan="'.$rowspan.'"'; + } $this->doc .= '>'; } @@ -966,7 +969,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->doc .= '</th>'; } - function tablecell_open($colspan = 1, $align = NULL){ + function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){ $class = 'class="col' . $this->_counter['cell_counter']++; if ( !is_null($align) ) { $class .= ' '.$align.'align'; @@ -977,6 +980,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $this->_counter['cell_counter'] += $colspan-1; $this->doc .= ' colspan="'.$colspan.'"'; } + if ( $rowspan > 1 ) { + $this->doc .= ' rowspan="'.$rowspan.'"'; + } $this->doc .= '>'; } |