I have installed and have been hackin' away at Kwiki as an experiment in documentation of the legacy systems and the inter-dependencies between them. So far, so good.

The first thing I stumbled upon was Kwiki tables. In tables, the rest of the text formations were not applied. So, if you wanted to have a table whose text was bolded or italicized or a link to another Wiki entry, you would attempt to enter something like:

|    |  *Bold Column Name* | *Another Bold Column Name* |
| 1 | a value | /italicized value/ |
| 2 | [WikiLink] | more stuff |

And, you ended up with a table that looked like:

 *Bold Column Name**Another Bold Column Name*
1a value/italicized value/
2[WikiLink]more stuff

What you wanted was:

 Bold Column NameAnother Bold Column Name
1a valueitalicized value
2WikiLinkmore stuff

No matter, Kwiki is written in Perl, and Kwiki is pluggable / extendable. Create a file in the same directory as your Kwiki installation; call it 'TableFormatter.pm'; and add the following code:

package TableFormatter;
$VERSION='0.1';
use base 'CGI::Kwiki::Formatter';

sub table {
    my ($self, $text) = @_;
    my @array;
    while ($text =~ /(.*?)(^\|[^\n]*\|\n.*)/ms) {
        push @array, $1;
        my @table = $self->parse_table($2);
        $text = pop @table;
        push @array, @table;
    }
    push @array, $text if length $text;
    return @array;
}

sub format_table {
   my ($self, $rows) = @_;
   my $cols = 0;
   for (@$rows) {
       $cols = @$_ if @$_ > $cols;
   }
   my @table = (\qq{<blockquote>\n<table border="1">\n});
   for my $row (@$rows) {
       push @table, \qq{<tr valign="top">\n};
       for (my $i = 0; $i < @$row; $i++) {
           my $colspan = '';
           if ($i == $#{$row} and $cols - $i > 1) {
               $colspan = ' colspan="' . ($cols - $i) . '"';
           } 
           my @cell = $row->[$i];
           $cell = \'<pre>', $cell, \qq{</pre>\n}
             if "@cell" =~ /\n/;
           @cell = (' ') unless length "@cell";
           push @table, \qq{<td$colspan>}, @cell, \qq{</td>\n};
       }
       push @table, \qq{</tr>\n};
   }
   push @table, \qq{</table></blockquote>\n};
   return @table;
}

sub process_order {
   return qw(
       function
       code
       header_1 header_2 header_3 header_4 header_5 header_6
       escape_html
       paragraph
       table
       lists comment horizontal_line
       named_http_link no_http_link http_link
       no_mailto_link mailto_link
       no_wiki_link force_wiki_link wiki_link
       inline version negation
       bold italic underscore
   );
}
1;

*Update*: I forgot to mention. After doing that, pop open your config.yaml file and change the line formatter_class: CGI::Kwiki::Formatter to formatter_class: TableFormatter.


J$


$a="A"and$'_="J";map{$a++}(66..ord
);$$_='$';print$'a,$$a

Trackbacks

Comments