From 67f9913d4a386fe65c9e72ca452b0fa91b010b12 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 15 Jan 2010 12:18:43 +0100 Subject: removed deprecated PHP4 construct Assigning the return value of new by reference is deprecated, PHP5's new automatically assigns by reference --- inc/parser/handler.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 9fe5866ad..eaa42f9bf 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -20,7 +20,7 @@ class Doku_Handler { var $rewriteBlocks = true; function Doku_Handler() { - $this->CallWriter = & new Doku_Handler_CallWriter($this); + $this->CallWriter = new Doku_Handler_CallWriter($this); } function _addCall($handler, $args, $pos) { @@ -47,7 +47,7 @@ class Doku_Handler { } if ( $this->rewriteBlocks ) { - $B = & new Doku_Handler_Block(); + $B = new Doku_Handler_Block(); $this->calls = $B->process($this->calls); } @@ -212,7 +212,7 @@ class Doku_Handler { $this->_footnote = true; - $ReWriter = & new Doku_Handler_Nest($this->CallWriter,'footnote_close'); + $ReWriter = new Doku_Handler_Nest($this->CallWriter,'footnote_close'); $this->CallWriter = & $ReWriter; $this->_addCall('footnote_open', array(), $pos); break; @@ -240,7 +240,7 @@ class Doku_Handler { function listblock($match, $state, $pos) { switch ( $state ) { case DOKU_LEXER_ENTER: - $ReWriter = & new Doku_Handler_List($this->CallWriter); + $ReWriter = new Doku_Handler_List($this->CallWriter); $this->CallWriter = & $ReWriter; $this->_addCall('list_open', array($match), $pos); break; @@ -302,7 +302,7 @@ class Doku_Handler { function preformatted($match, $state, $pos) { switch ( $state ) { case DOKU_LEXER_ENTER: - $ReWriter = & new Doku_Handler_Preformatted($this->CallWriter); + $ReWriter = new Doku_Handler_Preformatted($this->CallWriter); $this->CallWriter = & $ReWriter; $this->_addCall('preformatted_start',array(), $pos); break; @@ -328,7 +328,7 @@ class Doku_Handler { switch ( $state ) { case DOKU_LEXER_ENTER: - $ReWriter = & new Doku_Handler_Quote($this->CallWriter); + $ReWriter = new Doku_Handler_Quote($this->CallWriter); $this->CallWriter = & $ReWriter; $this->_addCall('quote_start',array($match), $pos); break; @@ -580,7 +580,7 @@ class Doku_Handler { case DOKU_LEXER_ENTER: - $ReWriter = & new Doku_Handler_Table($this->CallWriter); + $ReWriter = new Doku_Handler_Table($this->CallWriter); $this->CallWriter = & $ReWriter; $this->_addCall('table_start', array(), $pos); -- cgit v1.2.3 From 07c2b1c7ce9255456bf19c45cf9d34452cec2af1 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 19 Nov 2009 15:06:19 +0100 Subject: Add TABLE range marker for table editing darcs-hash:20091119140619-e4919-15efddc768526a6c1f6472f83ede17019144ffa3.gz --- inc/parser/handler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index eaa42f9bf..ea5a69b35 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -589,10 +589,11 @@ class Doku_Handler { } else { $this->_addCall('tablecell', array(), $pos); } + $this->status['table_begin'] = $pos; break; case DOKU_LEXER_EXIT: - $this->_addCall('table_end', array(), $pos); + $this->_addCall('table_end', array($this->status['table_begin']+1, $pos), $pos); $this->CallWriter->process(); $ReWriter = & $this->CallWriter; $this->CallWriter = & $ReWriter->CallWriter; @@ -1222,7 +1223,7 @@ class Doku_Handler_Table { } function tableEnd($call) { - $this->tableCalls[] = array('table_close',array(),$call[2]); + $this->tableCalls[] = array('table_close',$call[1],$call[2]); $this->finalizeTable(); } -- cgit v1.2.3 From 8af66ab927067b9d8f9d71963e266a08967fa9d1 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 29 Jan 2010 17:08:40 +0100 Subject: table: Remove redundant parser data, update tests --- inc/parser/handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index ea5a69b35..141cbcaf0 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1205,7 +1205,7 @@ class Doku_Handler_Table { $this->tableCell($call); break; case 'table_end': - $this->tableRowClose(array('tablerow_close',$call[1],$call[2])); + $this->tableRowClose(array('tablerow_close', array())); $this->tableEnd($call); break; default: -- cgit v1.2.3 From 90df9a4d69a2e467433b419b94fe799d11590539 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 4 Feb 2010 14:50:10 +0100 Subject: Rewrite section edit handling according to #1860 --- inc/parser/handler.php | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 141cbcaf0..b5d2baaab 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -12,9 +12,6 @@ class Doku_Handler { var $status = array( 'section' => false, - 'section_edit_start' => -1, - 'section_edit_level' => 1, - 'section_edit_title' => '' ); var $rewriteBlocks = true; @@ -40,10 +37,6 @@ class Doku_Handler { if ( $this->status['section'] ) { $last_call = end($this->calls); array_push($this->calls,array('section_close',array(), $last_call[2])); - if ($this->status['section_edit_start']>1) { - // ignore last edit section if there is only one header - array_push($this->calls,array('section_edit',array($this->status['section_edit_start'], 0, $this->status['section_edit_level'], $this->status['section_edit_title']), $last_call[2])); - } } if ( $this->rewriteBlocks ) { @@ -97,8 +90,6 @@ class Doku_Handler { } function header($match, $state, $pos) { - global $conf; - // get level and title $title = trim($match); $level = 7 - strspn($title,'='); @@ -108,13 +99,6 @@ class Doku_Handler { if ($this->status['section']) $this->_addCall('section_close',array(),$pos); - if ($level<=$conf['maxseclevel']) { - $this->_addCall('section_edit',array($this->status['section_edit_start'], $pos-1, $this->status['section_edit_level'], $this->status['section_edit_title']), $pos); - $this->status['section_edit_start'] = $pos; - $this->status['section_edit_level'] = $level; - $this->status['section_edit_title'] = $title; - } - $this->_addCall('header',array($title,$level,$pos), $pos); $this->_addCall('section_open',array($level),$pos); @@ -583,17 +567,16 @@ class Doku_Handler { $ReWriter = new Doku_Handler_Table($this->CallWriter); $this->CallWriter = & $ReWriter; - $this->_addCall('table_start', array(), $pos); + $this->_addCall('table_start', array($pos + 1), $pos); if ( trim($match) == '^' ) { $this->_addCall('tableheader', array(), $pos); } else { $this->_addCall('tablecell', array(), $pos); } - $this->status['table_begin'] = $pos; break; case DOKU_LEXER_EXIT: - $this->_addCall('table_end', array($this->status['table_begin']+1, $pos), $pos); + $this->_addCall('table_end', array($pos), $pos); $this->CallWriter->process(); $ReWriter = & $this->CallWriter; $this->CallWriter = & $ReWriter->CallWriter; @@ -1217,7 +1200,7 @@ class Doku_Handler_Table { } function tableStart($call) { - $this->tableCalls[] = array('table_open',array(),$call[2]); + $this->tableCalls[] = array('table_open',$call[1],$call[2]); $this->tableCalls[] = array('tablerow_open',array(),$call[2]); $this->firstCell = true; } @@ -1288,6 +1271,7 @@ class Doku_Handler_Table { // Adjust to num cols not num col delimeters $this->tableCalls[0][1][] = $this->maxCols - 1; $this->tableCalls[0][1][] = $this->maxRows; + $this->tableCalls[0][1][] = array_shift($this->tableCalls[0][1]); } else { trigger_error('First element in table call list is not table_open'); } @@ -1505,13 +1489,7 @@ class Doku_Handler_Block { //remove the whole paragraph array_splice($this->calls,$i); }else{ - if ($this->calls[count($this->calls)-1][0] == 'section_edit') { - $tmp = array_pop($this->calls); - $this->calls[] = array('p_close',array(), $pos); - $this->calls[] = $tmp; - } else { - $this->calls[] = array('p_close',array(), $pos); - } + $this->calls[] = array('p_close',array(), $pos); } $this->inParagraph = false; -- cgit v1.2.3 From 0139312b0d39e61bdff7318a0c092eb20b208a78 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 26 Mar 2010 13:16:46 +0100 Subject: Better code syntax parsing, less E_NOTICE --- inc/parser/handler.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index b5d2baaab..8639c5ad8 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -344,21 +344,16 @@ class Doku_Handler { function code($match, $state, $pos, $type='code') { if ( $state == DOKU_LEXER_UNMATCHED ) { $matches = explode('>',$match,2); - $matches[0] = trim($matches[0]); - - list($language,$filename) = explode(' ',$matches[0],2); - $language = trim($language); - $filename = trim($filename); - if ( $language == '' ) $language = null; - if ( $language == '-' ) $language = null; - if ( $filename == '' ) $filename = null; - # We shortcut html here. - if($language == 'html') $language = 'html4strict'; - $this->_addCall( - $type, - array($matches[1],$language,$filename), - $pos - ); + + $param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY); + while(count($param) < 2) array_push($param, null); + + // We shortcut html here. + if ($param[0] == 'html') $param[0] = 'html4strict'; + if ($param[0] == '-') $param[0] = null; + array_unshift($param, $matches[1]); + + $this->_addCall($type, $param, $pos); } return true; } -- cgit v1.2.3 From aa92c4ccfaf7462eb8f336c6a4e8e2b1468cfada Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 12 Aug 2010 13:46:14 +0200 Subject: clean up table parser handler --- inc/parser/handler.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 8639c5ad8..8de0c7490 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1175,7 +1175,7 @@ class Doku_Handler_Table { $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': @@ -1183,7 +1183,7 @@ class Doku_Handler_Table { $this->tableCell($call); break; case 'table_end': - $this->tableRowClose(array('tablerow_close', array())); + $this->tableRowClose($call); $this->tableEnd($call); break; default: @@ -1221,7 +1221,7 @@ class Doku_Handler_Table { break; } } - $this->tableCalls[] = $call; + $this->tableCalls[] = array('tablerow_close', array(), $call[2]); if ( $this->currentCols > $this->maxCols ) { $this->maxCols = $this->currentCols; @@ -1281,17 +1281,21 @@ class Doku_Handler_Table { // 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')); @@ -1315,8 +1319,9 @@ class Doku_Handler_Table { // 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; @@ -1336,8 +1341,9 @@ class Doku_Handler_Table { $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 @@ -1362,8 +1368,10 @@ class Doku_Handler_Table { $toDelete[] = $key-1; $toDelete[] = $key; - $toDelete[] = $key+1; + $toDelete[] = $key+1; } + break; + } } -- cgit v1.2.3 From 6606d6fc9f9fc0d581d23961ec634b24c7d41425 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 12 Aug 2010 14:03:43 +0200 Subject: Try to fix broken tables --- inc/parser/handler.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'inc/parser/handler.php') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 8de0c7490..0b8b79254 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1279,7 +1279,8 @@ class Doku_Handler_Table { // 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 - foreach ( $this->tableCalls as $key => $call ) { + for ($key = 0 ; $key < count($this->tableCalls) ; ++$key) { + $call = $this->tableCalls[$key]; switch ($call[0]) { case 'tablerow_open': @@ -1351,20 +1352,28 @@ class Doku_Handler_Table { } else { - $this->tableCalls[$key-1][1][2] = false; - + $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' ) { - if ( false !== $this->tableCalls[$cellKey[$i][$lastCell]][1][2] ) { - $this->tableCalls[$cellKey[$i][$lastCell]][1][2]++; + if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) { + $spanning_cell = $i; break; } } } + if (is_null($spanning_cell)) { + // No spanning cell found, so convert this cell to + // an empty one to avoid broken tables + $this->tableCells[$key][1][1] = ''; + continue; + } + $this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++; + + $this->tableCalls[$key-1][1][2] = false; $toDelete[] = $key-1; $toDelete[] = $key; @@ -1372,6 +1381,19 @@ class Doku_Handler_Table { } break; + case 'tablerow_close': + + // Fix broken tables by adding missing cells + while (++$lastCell < $this->maxCols) { + array_splice($this->tableCalls, $key, 0, array( + array('tablecell_open', array(1, null, 1), $call[2]), + array('cdata', array(''), $call[2]), + array('tablecell_close', array(), $call[2]))); + $key += 3; + } + + break; + } } -- cgit v1.2.3