00970: Table Formatting: THEAD, TBODY, TFOOT
Description:
This mod is complete / functional Files modified: pmwiki.php
- Functions modified: FormatTableRow() (lines 1314, 1317, 1326, 1327 & 1341), PZZ() (line 379)
- Variable Arrays modified: $BlockMarkups (line 278)
Reason for modification: Change SimpleTables format of
<table> <tr><td>!header</td><td>!header</td></tr> <tr><td>data</td><td>data</td></tr> <tr><td>data</td><td>data</td></tr> </table>
to
<table class="wikisimpletable"> <thead><tr><td>!header</td><td>!header</td></tr></thead> <tbody><tr><td>data</td><td>data</td></tr> <tr><td>data</td><td>data</td></tr></tbody> </table>
to account for formatting tables using thead, tbody, tfoot as noted at http://w3schools.com/html/html_tables.asp
- http://w3schools.com/tags/tag_thead.asp
- http://w3schools.com/tags/tag_tbody.asp
- http://w3schools.com/tags/tag_tfoot.asp
Example of what can be done when using such modifications: http://flyffchat.info/testingtable.html
original pmwiki.php: | modifications | |
---|---|---|
.. | ||
278 | 'table' => array("<table width='100%'>",'','</table>',0)); | 'table' => array("<table width='100%' class='wikisimpletable'>",'','</tbody></table>',0)); |
.. | ||
379 | function PZZ($x,$y='') { return ''; } | function PZZ($x,$y=) { $tt=;return ''; } |
.. | ||
1312 | function FormatTableRow($x, $sep = '\\|\\|') { | |
1313 | global $Block, $TableCellAttrFmt, $MarkupFrame, $TableRowAttrFmt, | |
1314 | $TableRowIndexMax, $FmtV; | $TableRowIndexMax, $FmtV, $tt; |
1315 | static $rowcount; | |
1316 | $x = preg_replace("/$sep\\s*$/",'',$x); | |
1317 | $td = preg_split("/$sep/", $x); $y = ''; | $td = preg_split("/$sep/", $x); $y = ''; if ($tt == 'tbody') $tt='e'; //e for end - outside of for loop on function call after var is set to prevent further 'tbody' |
1318 | for($i=0;$i<count($td);$i++) { | |
1319 | if ($td[$i]=='') continue; | |
1320 | $FmtV['$TableCellCount'] = $i; | |
1321 | $attr = FmtPageName(@$TableCellAttrFmt, ''); | |
1322 | $td[$i] = preg_replace('/^(!?)\\s+$/', '$1 ', $td[$i]); | |
1323 | if (preg_match('/^!(.*?)!$/',$td[$i],$match)) | |
1324 | { $td[$i]=$match[1]; $t='caption'; $attr=''; } | |
1325 | elseif (preg_match('/^!(.*)$/',$td[$i],$match)) | |
1326 | { $td[$i]=$match[1]; $t='th'; } | { $td[$i]=$match[1]; $t='th'; $tt='thead'; } |
1327 | else $t='td'; | else { $t='td'; $tt='tbody'; } |
1328 | if (preg_match('/^\\s.*\\s$/',$td[$i])) { $attr .= " align='center'"; } | |
1329 | elseif (preg_match('/^\\s/',$td[$i])) { $attr .= " align='right'"; } | |
1330 | elseif (preg_match('/\\s$/',$td[$i])) { $attr .= " align='left'"; } | |
1331 | for ($colspan=1;$i+$colspan<count($td);$colspan++) | |
1332 | if ($td[$colspan+$i]!='') break; | |
1333 | if ($colspan>1) { $attr .= " colspan='$colspan'"; } | |
1334 | $y .= "<$t $attr>".trim($td[$i])."</$t>"; | |
1335 | } | |
1336 | if ($t=='caption') return "<:table,1>$y"; | |
1337 | if (@$MarkupFrame[0]['cs'][0] != 'table') $rowcount = 0; else $rowcount++; | |
1338 | $FmtV['$TableRowCount'] = $rowcount + 1; | |
1339 | $FmtV['$TableRowIndex'] = ($rowcount % $TableRowIndexMax) + 1; | |
1340 | $trattr = FmtPageName(@$TableRowAttrFmt, ''); | |
1341 | return "<:table,1><tr $trattr>$y</tr>"; | if ($tt=='thead') return "<:table,1><$tt><tr $trattr>$y</tr></$tt>"; |
added | else if ($tt=='tbody') return "<:table,1><$tt><tr $trattr>$y</tr>"; | |
added | else return "<:table,1><tr $trattr>$y</tr>"; | |
1342 | } | |
.. |
So as to avoid results like http://flyffchat.info/testingtablewrong.html in which each row of <tr><td></td>...</tr>
gets its own tbody, I had to find a place to add code upon each table beginning. I used PZZ function (which appears to do nothing). It is called for other tasks unrelated to beginning of new SimpleTables, but it seems to be a good place to clear the $tt var.
Once $tt var is set to 'tbody', upon the next call of the FormatTableRow function, it is set to 'e' to prevent further inclusion of </tbody> on any further rows. The final </tbody> tag has been included in line 278.
function PZZ, even though unrelated, and seems to do nothing at all, is called from file stdmarkup.php line 379 each time a new simple table code is parsed. I modified that function to produce the results I was looking for.