Just a quick hack to for <th> tags in your tables. Not vigorously tested. Please suggest any alternate arrangements that might be more inline with the wikiwikiway.
Return to TaviPatches.
NB! As a response to this patch and my own ideas, I suggest reading TaviPatches/TableFormatting.
function html_table_header_start($span = 1){
if($span == 1)
{ return '<th>'; }
else
{ return '<th colspan="' . $span . '">'; }
}
function html_table_header_end()
{ return '</th>';
}
function parse_table($text)
{
static $in_table = 0;
$pre = '';
$post = '';
if(preg_match('/^(\|\|)+.*(\|\|)\s*$/', $text)) // Table.
{
if(!$in_table)
{
$pre = html_table_start();
$in_table = 1;
}
// first look for headers (||~)
$text = preg_replace('/^((\|\|)*\|\|\~)(.*)\|\|\s*$/e',
"new_entity(array('raw',html_table_row_start().html_table_header_start((strlen('\\1')-1)/2))).".
"q1('\\3').new_entity(array('raw',html_table_header_end().html_table_row_end()))",
$text, -1);
$text = preg_replace('/^((\|\|)+)(.*)\|\|\s*$/e',
"new_entity(array('raw',html_table_row_start().html_table_cell_start(strlen('\\1')/2))).".
"q1('\\3').new_entity(array('raw',html_table_cell_end().html_table_row_end()))",
$text, -1);
// first look for headers (||~)
$text = preg_replace('/((\|\|\~)+)/e',
"new_entity(array('raw',html_table_header_end().html_table_header_start(strlen('\\1')/2)))",
$text, -1);
// regular cells
$text = preg_replace('/((\|\|)+)/e',
"new_entity(array('raw',html_table_cell_end().html_table_cell_start(strlen('\\1')/2)))",
$text, -1);
}
else if($in_table) // Have exited table.
{
$in_table = 0;
$pre = html_table_end();
}
if($pre != '')
{ $text = new_entity(array('raw', $pre)) . $text; }
if($post != '')
{ $text = $text . new_entity(array('raw', $post)); }
return $text;
}
Header cells begin with double-pipes and a tilde ('||~')
||~headers cells ||~ begin with a tilde || ('||~') ||
||||~ headers can span multiple columns by || starting each cell ||
|| with extra cell |||| separators ||