summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-08-12 14:03:43 +0200
committerAdrian Lang <lang@cosmocode.de>2010-08-13 11:37:22 +0200
commit6606d6fc9f9fc0d581d23961ec634b24c7d41425 (patch)
tree7b438e99f914f16c236716c4a2ceb5d1a6bc3069 /inc/parser
parentaa92c4ccfaf7462eb8f336c6a4e8e2b1468cfada (diff)
downloadrpg-6606d6fc9f9fc0d581d23961ec634b24c7d41425.tar.gz
rpg-6606d6fc9f9fc0d581d23961ec634b24c7d41425.tar.bz2
Try to fix broken tables
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/handler.php32
1 files changed, 27 insertions, 5 deletions
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;
+
}
}