||First || Centered || Right|| ||A || B || C|| ||||Next is empty || C|| |||||| Summary ||
||class=wikitablefigure || upload:imgwiki.gif ||
This includes the Empty Cell Fix from WikiBugs/EmptyTableElements.
||First || Centered || Right|| ||A || B || C|| ||||Next is empty || C|| |||||| Summary ||
||class=wikitablefigure || upload:imgwiki.gif || || Figure Title ||
A sample css solution:
.wikitable, .wikitablefigure { margin: 0px; padding: 0px; width: 666px; border-style: solid; border-color: black; border-width: 1px 1px 1px 1px; border-collapse: collapse; } .wikitable td { margin: 0px; padding: 3px; border-style: solid; border-color: black; border-width: 0px 0px 1px 1px; } .wikitablefigure td { margin: 0px; padding: 3px; border-style: solid; border-color: black; border-width: 1px 1px 0px 0px; } .wikitable tr#Row0 td { color: white; background-color: black; border-left-color: white; } .wikitablefigure tr#Row1 td { color: white; background-color: black; border-right-color: white; }
After applying this patch, you can only use the wiki table syntax using || ||. Original HTML table syntax <table> <td> <tr> </table> does not work any longer. Because I need both, I decided no to apply this patch and to turn back to the original version.
Perhaps could the author elaborate on this ? --TomGries, 18.01.2004
Hi Mark, I need the raw HTML tables when I migrate contents of some of my existing HTML pages to my wiki. It's handy (and quick&dirty, I admit) to start from the HTML pages. Another wiki engine I know (tikiwiki) handles mixed pages with raw HTML tables and with || || tables (but of course separated from each other).
Perhaps a robust PERL script could convert raw HTML to || ||, but I don't know of such a script. TomGries 19.01.2004
It is still possible to use HTML tables after applying the patch. You just can't have any line breaks and you can't use the <nowiki> tag. At least, that's my experience. JayLarson
What about table header? Other Wikis (look at Wikipedia ;-)) use !! instead of || to create <th> instead of <td>. -- Roker
I changed line
s/^((\|\|)+)(.*)\|\|\s*$/"<TR id='Row$rowNumber' " . "><TD colspan='" . (length($1)\/2) . "'>" . &EmptyCellFixing($3) . "<\/TD><\/TR>\n"/e) {to
s/^(\?(\w+))?((\|\|)+)(.*)\|\|\s*$/"<TR id='Row$rowNumber' " . ($1 ? "class='$2' " : "") . "><TD colspan='" . (length($3)\/2) . "'>" . &EmptyCellFixing($5) . "<\/TD><\/TR>\n"/e) {Now you can use "?xyz" in front of the table row to set the css class for the row. Thought I'd share this with the community. -- HeinrichMoser?
--- wiki.1.0.0.pl Thu Sep 12 10:53:14 2002 +++ wikipatch.TableFormatting.pl Thu Jan 22 13:39:06 2004 @@ -1602,7 +1602,7 @@ my ($text, $useImage, $doLines) = @_; local $_ = $text; - if ($doLines < 2) { # 2 = do line-oriented only + if ($doLines) { # 0 = no line-oriented, 1 or 2 = do line-oriented (PATCH) # The <nowiki> tag stores text with no markup (except quoting HTML) s/\<nowiki\>((.|\n)*?)\<\/nowiki\>/&StoreRaw($1)/ige; # The <pre> tag wraps the stored text with the HTML <pre> tag @@ -1685,21 +1685,36 @@ } if ($TableMode) { s/((\|\|)+)/"<\/TD><TD COLSPAN=\"" . (length($1)\/2) . "\">"/ge; + my %alignments = (',', '', + ', ', ' align="left"', + ' ,', ' align="right"', + ' , ', ' align="center"', + ); + s/<td(.*?)>( )?(.*?)( )?<\/td>/"<td".($alignments{"$2,$4"})."$1>$3<\/td>"/gei; } } return $_; } +sub EmptyCellFixing { + my ($table) = @_; + $table =~ s/(?<=\|\|)(\s+)(?=\|\|)/ /g; + $table =~ s/^(\s+)(?=\|\|)/ /; + $table =~ s/(?<=\|\|)(\s+)$/ /; + return $table; +} + sub WikiLinesToHtml { my ($pageText) = @_; my ($pageHtml, @htmlStack, $code, $codeAttributes, $depth, $oldCode); @htmlStack = (); $depth = 0; + my $rowNumber = 0; $pageHtml = ""; + $codeAttributes = ''; foreach (split(/\n/, $pageText)) { # Process lines one-at-a-time $code = ''; - $codeAttributes = ''; $TableMode = 0; $_ .= "\n"; if (s/^(\;+)([^:]+\:?)\:/<dt>$2<dd>/) { @@ -1714,12 +1729,16 @@ } elsif (s/^(\#+)/<li>/) { $code = "OL"; $depth = length $1; + } elsif ($TableSyntax && s/^\|\|\s*([^\|]*)$//) { + $rowNumber = 0; + $TableMode = 1; + $codeAttributes = $1; } elsif ($TableSyntax && - s/^((\|\|)+)(.*)\|\|\s*$/"<TR VALIGN='CENTER' " - . "ALIGN='CENTER'><TD colspan='" - . (length($1)\/2) . "'>$3<\/TD><\/TR>\n"/e) { + s/^((\|\|)+)(.*)\|\|\s*$/"<TR id='Row$rowNumber' " . "><TD colspan='" + . (length($1)\/2) . "'>" . &EmptyCellFixing($3) . "<\/TD><\/TR>\n"/e) { + $rowNumber++; $code = 'TABLE'; - $codeAttributes = "BORDER='1'"; + $codeAttributes .= ($codeAttributes =~ m/class=/) ? "" : " class='wikitable'"; $TableMode = 1; $depth = 1; } elsif (/^[ \t].*\S/) { @@ -1728,6 +1747,7 @@ } else { $depth = 0; } + $codeAttributes = '' unless $TableMode; while (@htmlStack > $depth) { # Close tags as needed $pageHtml .= "</" . pop(@htmlStack) . ">\n"; }
if ($doLines < 2) { # 2 = do line-oriented only
It's distinctly possible that I'm doing something wrong, of course. But it works beautifully for me with that change, and even better with the following additional change to reset the row number counter on closing a table (so that, with multiple tables on a page, each table gets the Row0 id for its first row).
In WikiLinesToHtml:
while (@htmlStack > $depth) { # Close tags as needed + if ( $htmlStack[-1] =~ /^TABLE/i ) { + $rowNumber = 0; + }
$pageHtml .= "</" . pop(@htmlStack) . ">\n"; }
Figure Title |
A sample css solution:
.wikitable, .wikitablefigure { margin: 0px; padding: 0px; width: 666px; border-style: solid; border-color: black; border-width: 1px 1px 1px 1px; border-collapse: collapse; } .wikitable td { margin: 0px; padding: 3px; border-style: solid; border-color: black; border-width: 0px 0px 1px 1px; } .wikitablefigure td { margin: 0px; padding: 3px; border-style: solid; border-color: black; border-width: 1px 1px 0px 0px; } .wikitable tr#Row0 td { color: white; background-color: black; border-left-color: white; } .wikitablefigure tr#Row1 td { color: white; background-color: black; border-right-color: white; }