X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/0d108e74d9b48ba080c128407eed3c787edec1bd..8ded9f57a12a27fa5fc1e272ec7b2d2a5aa28419:/IkiWiki/Plugin/table.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/table.pm b/IkiWiki/Plugin/table.pm index c5404aa85..e782fc238 100644 --- a/IkiWiki/Plugin/table.pm +++ b/IkiWiki/Plugin/table.pm @@ -3,80 +3,93 @@ package IkiWiki::Plugin::table; use warnings; use strict; - -use IkiWiki; -use IkiWiki::Plugin::mdwn; +use Encode; +use IkiWiki 2.00; sub import { #{{{ + hook(type => "getsetup", id => "table", call => \&getsetup); hook(type => "preprocess", id => "table", call => \&preprocess); } # }}} +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, +} #}}} + sub preprocess (@) { #{{{ my %params =( - format => 'auto', - header => 'yes', + format => 'auto', + header => 'row', @_ ); if (exists $params{file}) { if (! $pagesources{$params{file}}) { - return "[[table ".gettext("cannot find file")."]]"; + error gettext("cannot find file"); } $params{data} = readfile(srcfile($params{file})); + add_depends($params{page}, $params{file}); } if (lc $params{format} eq 'auto') { # first try the more simple format if (is_dsv_data($params{data})) { $params{format} = 'dsv'; - $params{sep_char}->{dsv} = '|'; } else { $params{format} = 'csv'; - $params{sep_char}->{csv} = ','; } } my @data; if (lc $params{format} eq 'csv') { - @data=split_csv($params{data}, $params{delimiter}); + @data=split_csv($params{data}, + defined $params{delimiter} ? $params{delimiter} : ",",); + # linkify after parsing since html link quoting can + # confuse CSV parsing + if (! exists $params{file}) { + @data=map { + [ map { + IkiWiki::linkify($params{page}, + $params{destpage}, $_); + } @$_ ] + } @data; + } } elsif (lc $params{format} eq 'dsv') { - @data=split_dsv($params{data}, $params{delimiter}); + # linkify before parsing since wikilinks can contain the + # delimiter + if (! exists $params{file}) { + $params{data} = IkiWiki::linkify($params{page}, + $params{destpage}, $params{data}); + } + @data=split_dsv($params{data}, + defined $params{delimiter} ? $params{delimiter} : "|",); } else { - return "[[table ".gettext("unknown data format")."]]"; + error gettext("unknown data format"); } my $header; - if (lc($params{header}) eq "yes") { + if (lc($params{header}) eq "row" || IkiWiki::yesno($params{header})) { $header=shift @data; } if (! @data) { - return "[[table ".gettext("empty data")."]]"; + error gettext("empty data"); } my @lines; push @lines, defined $params{class} ? "
". - htmlize($params{page}, $params{destpage}, $_). - " | " - } @$header), - "\t\t
---|
". - htmlize($params{page}, $params{destpage}, $_). - " | " - } @$record), - "\t\t
!!; - $text=~s!
$!!; - chomp $text; + if ($colspan > 1) { + push @ret, "\t\t\t<$e colspan=\"$colspan\">$cell$e>" + } + else { + push @ret, "\t\t\t<$e>$cell$e>" + } + } + push @ret, "\t\t