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?.

  1. Add the functions indicated below to parse/html.php.
  2. Add the function parse_table, whose source is below, to parse/transforms.php.
  3. Add 'parse_table' to the $ParseEngine array in config.php. You should put it after the 'parse_heading' line and before the 'parse_horiz' line.

Return to TaviPatches.


parse/html.php

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>'; }

parse/transforms.php

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;
}