[Home]WikiPatches/TableRowSpan

UseModWiki | WikiPatches | RecentChanges | Preferences

Here's a simple patch to add rowspan -- put an exclamation mark (!) after the last pipe (|), more exclamation marks means more spanning.

replace this line (search for 'COLSPAN'):

s/((\|\|)+)/"<\/TD><TD COLSPAN=\"" . (length($1)\/2) . "\">"/ge;
with this line:
s/((\|\|)+)((\!)*)/"<\/TD><TD COLSPAN=\"" . (length($1)\/2) . "\" ROWSPAN=\"" . (length($3)+1) . "\">"/ge;
and replace this line (search for 'colspan'):
} elsif ($TableSyntax &&
             s/^((\|\|)+)(.*)\|\|\s*$/"<TR VALIGN='CENTER' "
                                      . "ALIGN='CENTER'><TD colspan='"
                               . (length($1)\/2) . "'>$3<\/TD><\/TR>\n"/e) {
with this line:
} elsif ($TableSyntax &&
             s/^((\|\|)+)((\!)*)(.*)\|\|\s*$/"<TR VALIGN=\"CENTER\" "
                                      . "ALIGN=\"CENTER\"><TD COLSPAN=\""
                               . (length($1)\/2) . "\" ROWSPAN=\"" . (length($3)+1) . "\">$5<\/TD><\/TR>\n"/e) {
I've tested this with UseMod 1.0, seems to work fine. I just really wanted rowspan on a table one day, so I threw this together. Very simple but it works.

-- Michael Rienstra 2006-02-13


Bravo, a very elegant patch!

One minor nitpick: you could replace

. "\" ROWSPAN=\"" . (length($3)+1)
with
. (length($3) ? "\" ROWSPAN=\"" . (length($3)+1) : '')
This way, extraneous ROWSPAN="1" tags will not be generated.

-- UngarPeter


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