summaryrefslogtreecommitdiff
path: root/support/easylatex/wikiLatexToEasyLatexTables.pl
blob: 6ba4359d25e1355a493fd94183f06c9b53a348ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl -i 

undef $/;
$file = <>;

$tableLineRE = '\|\|([^\|\n]*?)(\|\|[^\|\n]*?)*?\|\|'."\n";
$file =~ s/($tableLineRE($tableLineRE)+)/processTable($1)/eg;
#$file =~ s/(.*|\n)*/'I found a table!'/gsm;

print $file;



sub processTable {
    my ($table) = @_;

    $table =~ /(.*)/;
    $tableLine1 = $1;
    
    $dividerCount = 0;
    while ($tableLine1 =~ /\|\|/g) {
	$dividerCount = $dividerCount + 1;}
    $colCount = $dividerCount - 1;

    $colSpec = '|l'.('|l' x ($colCount - 1)).'|';

    $table =~ s/^\|\|(.*)\|\|$/$1/gm;
    $table =~ s/\|\|/&/g;
    $table =~ s/\n/\\\\\n/g;

    $table = "\\begin{tabular}{$colSpec}\n".'\hline'."\n".$table.'\hline'."\n".'\end{tabular}';

    return $table;
}

#todo: add this to easylatex