summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/inc/parser/parser_table.test.php152
-rw-r--r--inc/parser/handler.php63
-rw-r--r--inc/parser/metadata.php4
-rw-r--r--inc/parser/parser.php2
-rw-r--r--inc/parser/renderer.php4
-rw-r--r--inc/parser/xhtml.php10
6 files changed, 154 insertions, 81 deletions
diff --git a/_test/cases/inc/parser/parser_table.test.php b/_test/cases/inc/parser/parser_table.test.php
index 5b8b363f8..f84923dfd 100644
--- a/_test/cases/inc/parser/parser_table.test.php
+++ b/_test/cases/inc/parser/parser_table.test.php
@@ -21,24 +21,24 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
@@ -61,24 +61,24 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
@@ -130,13 +130,13 @@ def');
array('p_close',array()),
array('table_open',array(3,1)),
array('tablerow_open',array()),
- array('tableheader_open',array(1,NULL)),
+ array('tableheader_open',array(1,NULL,1)),
array('cdata',array(' X ')),
array('tableheader_close',array()),
- array('tablecell_open',array(1,NULL)),
+ array('tablecell_open',array(1,NULL,1)),
array('cdata',array(' Y ')),
array('tablecell_close',array()),
- array('tableheader_open',array(1,NULL)),
+ array('tableheader_open',array(1,NULL,1)),
array('cdata',array(' Z ')),
array('tableheader_close',array()),
array('tablerow_close',array()),
@@ -165,13 +165,13 @@ def');
array('p_close',array()),
array('table_open',array(3,1)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'right')),
+ array('tablecell_open',array(1,'right',1)),
array('cdata',array(' X ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Y ')),
array('tablecell_close',array()),
- array('tableheader_open',array(1,'center')),
+ array('tableheader_open',array(1,'center',1)),
array('cdata',array(' Z ')),
array('tableheader_close',array()),
array('tablerow_close',array()),
@@ -201,18 +201,18 @@ def');
array('p_close',array()),
array('table_open',array(3,3)),
array('tablerow_open',array()),
- array('tablecell_open',array(2,'right')),
+ array('tablecell_open',array(2,'right',1)),
array('cdata',array(' d ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,NULL)),
+ array('tablecell_open',array(1,NULL,1)),
array('cdata',array(' e ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,NULL)),
+ array('tablecell_open',array(1,NULL,1)),
array('cdata',array(' f ')),
array('tablecell_close',array()),
- array('tableheader_open',array(2,NULL)),
+ array('tableheader_open',array(2,NULL,1)),
array('cdata',array(' ')),
array('tableheader_close',array()),
array('tablerow_close',array()),
@@ -227,6 +227,54 @@ def');
$this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
}
+ function testCellRowSpan() {
+ $this->P->addMode('table',new Doku_Parser_Mode_Table());
+ $this->P->parse('
+abc
+| a | c:::||
+|:::^ d | e|
+|b ^ ::: |:::f|
+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)),
+ array('tablerow_open',array()),
+ array('tablecell_open',array(1,NULL,2)),
+ array('cdata',array(' a ')),
+ array('tablecell_close',array()),
+ array('tablecell_open',array(2,'right',1)),
+ array('cdata',array(' c:::')),
+ array('tablecell_close',array()),
+ array('tablerow_close',array()),
+ array('tablerow_open',array()),
+ array('tableheader_open',array(1,'left',2)),
+ array('cdata',array(' d ')),
+ array('tableheader_close',array()),
+ array('tablecell_open',array(1,NULL,1)),
+ array('cdata',array(' e')),
+ array('tablecell_close',array()),
+ array('tablerow_close',array()),
+ array('tablerow_open',array()),
+ array('tablecell_open',array(1,'left',1)),
+ array('cdata',array('b ')),
+ array('tablecell_close',array()),
+ array('tablecell_open',array(1,NULL,1)),
+ array('cdata',array(':::f')),
+ array('tablecell_close',array()),
+ array('tablerow_close',array()),
+ array('table_close',array()),
+ array('p_open',array()),
+ array('cdata',array('def'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
function testCellAlignmentFormatting() {
$this->P->addMode('table',new Doku_Parser_Mode_Table());
$this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong'));
@@ -242,17 +290,17 @@ def');
array('p_close',array()),
array('table_open',array(3,1)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'right')),
+ array('tablecell_open',array(1,'right',1)),
array('cdata',array(' ')),
array('strong_open',array()),
array('cdata',array('X')),
array('strong_close',array()),
array('cdata',array(' ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Y ')),
array('tablecell_close',array()),
- array('tableheader_open',array(1,'center')),
+ array('tableheader_open',array(1,'center',1)),
array('cdata',array(' Z ')),
array('tableheader_close',array()),
array('tablerow_close',array()),
@@ -282,24 +330,24 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
@@ -329,14 +377,14 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' ')),
array('strong_open',array()),
array('cdata',array('Row 0 Col 1')),
array('strong_close',array()),
array('cdata',array(' ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' ')),
array('strong_open',array()),
array('cdata',array('Row 0 Col 2 | Row 0 Col 3')),
@@ -345,13 +393,13 @@ def');
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
@@ -381,25 +429,25 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' ')),
array('unformatted',array('Row 0 Col 1')),
array('cdata',array(' ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' ')),
array('unformatted',array('Row 0 Col 2 | Row 0 Col 3')),
array('cdata',array(' ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
@@ -427,26 +475,26 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0')),
array('linebreak',array()),
array('cdata',array('Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 0 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
@@ -477,7 +525,7 @@ def');
array('p_close',array()),
array('table_open',array(3,2)),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' ')),
array('nest', array ( array (
array('footnote_open',array()),
@@ -486,7 +534,7 @@ def');
))),
array('cdata',array(' ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' ')),
array('nest', array ( array (
array('footnote_open',array()),
@@ -497,13 +545,13 @@ def');
array('tablecell_close',array()),
array('tablerow_close',array()),
array('tablerow_open',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 1 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 2 ')),
array('tablecell_close',array()),
- array('tablecell_open',array(1,'left')),
+ array('tablecell_open',array(1,'left',1)),
array('cdata',array(' Row 1 Col 3 ')),
array('tablecell_close',array()),
array('tablerow_close',array()),
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 .= '>';
}