This patch is part of the main codebase starting in version 0.21. To incorporate table syntax into version 0.20, apply the following patch. The inspiration for this patch is SunirShah's implementation of usemod:WikiPatches/TableSyntax?.
Return to TaviPatches.
function html_table_start()
{ return '<table border="1">'; }
function html_table_end()
{ return '</table>'; }
function html_table_row_start()
{ return '<tr>'; }
function html_table_row_end()
{ return '</tr>'; }
function html_table_cell_start($span = 1)
{
if($span == 1)
{ return '<td>'; }
else
{ return '<td colspan="' . $span . '">'; }
}
function html_table_cell_end()
{ return '</td>'; }
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;
}
$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);
$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;
}