From: <var...@us...> - 2010-11-09 13:20:23
|
Revision: 7732 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=7732&view=rev Author: vargenau Date: 2010-11-09 13:20:16 +0000 (Tue, 09 Nov 2010) Log Message: ----------- Better handling of <thead> Modified Paths: -------------- trunk/lib/plugin/MediawikiTable.php Modified: trunk/lib/plugin/MediawikiTable.php =================================================================== --- trunk/lib/plugin/MediawikiTable.php 2010-11-09 12:47:18 UTC (rev 7731) +++ trunk/lib/plugin/MediawikiTable.php 2010-11-09 13:20:16 UTC (rev 7732) @@ -76,8 +76,19 @@ $argstr = str_replace("!!", "\n! ", $argstr); $lines = explode("\n", $argstr); + $table = HTML::table(); + $caption = HTML::caption(); + $thead = HTML::thead(); + $tbody = HTML::tbody(); + // Do we need a <thead>? + // 0 = unknown + // 1 = inside (parsing cells) + // 2 = false (no thead, only tbody) + // 3 = true (there is a thead) + $theadstatus = 0; + // We always generate an Id for the table. // This is convenient for tables of class "sortable". // If user provides an Id, the generated Id will be overwritten below. @@ -104,7 +115,7 @@ return HTML::raw(''); } - foreach ($lines as $line){ + foreach ($lines as $line) { if (substr($line,0,2) == "|}") { // End of table continue; @@ -124,11 +135,9 @@ unset($cell); } if (!empty($row->_content)) { - if (isset($thead)) { + if ($theadstatus == 1) { // inside + $theadstatus = 3; // true $thead->pushContent($row); - $table->pushContent($thead); - unset($thead); - $tbody = HTML::tbody(); } else { $tbody->pushContent($row); } @@ -154,7 +163,6 @@ // Table caption if (substr($line,0,2) == "|+") { - $caption = HTML::caption(); $line = substr($line,2); $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); @@ -170,7 +178,6 @@ } $caption->pushContent(trim($line)); - $table->pushContent($caption); } if (((substr($line,0,1) == "|") or (substr($line,0,1) == "!")) and isset($row)) { @@ -186,11 +193,15 @@ $row->pushContent($cell); } if (substr($line,0,1) == "!") { + if ($theadstatus == 0) { // unknown + $theadstatus = 1; // inside + } $cell = HTML::th(); // Header - $thead = HTML::thead(); } else { + if ($theadstatus == 1) { // inside + $theadstatus = 2; // false + } $cell = HTML::td(); - if (!isset($tbody)) $tbody = HTML::tbody(); } $line = substr($line, 1); @@ -252,11 +263,17 @@ if (!empty($row->_content)) { $tbody->pushContent($row); } - if (isset($tbody) && !empty($tbody->_content)) { - $table->pushContent($tbody); - } } - if (isset($table) && !empty($table->_content)) { + if (!empty($caption->_content)) { + $table->pushContent($caption); + } + if (!empty($thead->_content)) { + $table->pushContent($thead); + } + if (!empty($tbody->_content)) { + $table->pushContent($tbody); + } + if (!empty($table->_content)) { return $table; } else { return HTML::raw(''); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |