[Home]WikiPatches/SimpleTables

UseModWiki | WikiPatches | RecentChanges | Preferences

See also WikiPatches/TableSyntax.

An enhancement, not a bugfix. This enables usemod to render simple tables. Tables are handled somewhat like text within "<pre> </pre>".

Note that this patch doesn't work with 0.92 as it sets 'use strict', and the patch uses a global variable $tag. To make it work, you need to add $tag to the 'my' declaration right after the 'sub WikiLinesToHtml'. -- Viktor Haag

Sorry, I must have lost the line "my ($tag);" somehow. Patch now repaired --HaJoGurt
| Col1 | Col2 | Col3
gets formatted as
 <TABLE BORDER=0>
 <TR><TD> Col1</TD>
 <td> Col2 </td>
 <td> Col3
 </td>
 </TR>
 </table>
The Patch:
sub CommonMarkup {
...
## Tables:
    s/^\|([^|]+)[^|]/<TR><TD>$1<\/TD>\n/g;      # start of line: new table-row
    s/\|([^|]+)[^|]/<td>$1<\/td>\n/g;           # new field
  }
  return $_;
}
sub WikiLinesToHtml {
...
  my ($tag);
...
    } elsif (/^[ \t].*\S/) {
      $code = "PRE";
      $depth = 1;
#%% Table => PRE:
    } elsif (/^[\|\+].*\S/) {
      $code = "TABLE";
      $depth = 1;
#
    } else {
      $depth = 0;
    }
    while (@htmlStack > $depth) {   # Close tags as needed
    # $pageHtml .=  "</" . pop(@htmlStack) . ">\n";
#%%
      $tag = pop(@htmlStack);
      if ($tag eq "TABLE") {
        $pageHtml .=  "</TR>\n";
        $tag = "table"
      };
      $pageHtml .=  "</" . $tag . ">\n";
    }
    if ($depth > 0) {
      $depth = $IndentLimit  if ($depth > $IndentLimit);
...#!
      while (@htmlStack < $depth) {
        push(@htmlStack, $code);
#%%
        if ($code eq "TABLE") {
          $pageHtml .= "<TABLE BORDER=0>\n";
        } else {
          $pageHtml .= "<$code>\n";
        };
      }
    }
Next project: Specify different styles, like FONT and BGCOLOR, for each row, column and/or cell :-) By the way, the original code at "...#!" above can be left out. I think that will fix a bug with mixed / nested lists :
# Foo
** Ding
** Dong
# Bar
** Ping
** Pong
----
* Foo
## Ding
## Dong
* Bar
## Ping
## Pong
will then look like:
    1. Foo
          + Ding
          + Dong
    2. Bar
          + Ping
          + Pong
----
     * Foo
         1. Ding
         2. Dong
     * Bar
         1. Ping
         2. Pong
--HaJoGurt

Thanks for this patch! I finally got around to incorporating it in my wiki. I tweaked the regexps a bit though. I changed the fragment ([^|]+)[^|] to ([^|]+)\s* in both places where it occurs. This way the last character of a cell value is not truncated, and all trailing whitespace is ignored. I prefer this because I don't want to require a space before a separator, and I want to use extra space to line things up in the source. (Eliding the extra spaces doesn't seem to be important, though.) Also, I chose to use <TABLE BORDER=2> instead of zero, since I wanted a visible border. - DanMuller

The tables work. However, this patch does not allow cells spanning more than one column. That's the main reason why I prefer the patch at WikiPatches/TableSyntax. And it doesn't require spaces around separators as well.
The patch for mixed / nested lists doesn't work in my case, whatever I try. How can this be accomplished? --DavidAndel

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited October 2, 2007 9:07 pm by JuanmaMP (diff)
Search: