1 # Copyright (C) 2004, 2005 Alex Schroeder <alex@emacswiki.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 # Free Software Foundation, Inc.
16 # 59 Temple Place, Suite 330
17 # Boston, MA 02111-1307 USA
19 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/tables-in-lists.pl">tables-in-lists.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Table_Markup_Extension">Table Markup Extension</a></p>';
21 push(@MyRules, \
&TablesInListsRule
);
23 sub TablesInListsRule
{
24 # tables using || -- the first row of a table inside a list
25 if ($bol && m/\G((\|\|)+)([ \t])*(?=.*\|\|[ \t]*(\n|$))/cg) {
27 if (InElement
('li')) {
28 return CloseHtmlEnvironmentUntil
('li')
29 . AddHtmlEnvironment
('table', 'class="user"')
30 . AddHtmlEnvironment
('tr', 'class="odd first"')
31 . AddHtmlEnvironment
('td', UsemodTableAttributes
(length($1)/2, $3));
33 return OpenHtmlEnvironment
('table',1,'user')
34 . AddHtmlEnvironment
('tr', 'class="odd first"')
35 . AddHtmlEnvironment
('td', UsemodTableAttributes
(length($2)/2, $4));
38 # tables using || -- end of the row and beginning of the next row
39 elsif (InElement
('td') && m/\G[ \t]*((\|\|)+)[ \t]*\n((\|\|)+)([ \t]*)/cg) {
40 my $attr = UsemodTableAttributes
(length($3)/2, $5);
41 my $type = ++$rowcount % 2 ?
'odd' : 'even';
42 $attr = " " . $attr if $attr;
43 return qq{</td></tr
><tr
class="$type"><td
$attr>};
45 # tables using || -- an ordinary table cell
46 elsif (InElement
('td') && m/\G[ \t]*((\|\|)+)([ \t]*)(?!(\n|$))/cg) {
47 my $attr = UsemodTableAttributes
(length($1)/2, $3);
48 $attr = " " . $attr if $attr;
49 return "</td><td$attr>";
51 # tables using || -- since "next row" was taken care of above, this must be the last row
52 elsif (InElement
('td') && m/\G[ \t]*((\|\|)+)[ \t]*/cg) {
53 if (InElement
('li')) {
54 return CloseHtmlEnvironmentUntil
('li');
56 return CloseHtmlEnvironments
() . AddHtmlEnvironment
('p');
59 return undef; # sonst geht Oddmuse in eine Endlosschleife