summaryrefslogtreecommitdiff
path: root/support/easylatex/wikiLatexToEasyLatexTables.pl
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/easylatex/wikiLatexToEasyLatexTables.pl
Initial commit
Diffstat (limited to 'support/easylatex/wikiLatexToEasyLatexTables.pl')
-rwxr-xr-xsupport/easylatex/wikiLatexToEasyLatexTables.pl36
1 files changed, 36 insertions, 0 deletions
diff --git a/support/easylatex/wikiLatexToEasyLatexTables.pl b/support/easylatex/wikiLatexToEasyLatexTables.pl
new file mode 100755
index 0000000000..6ba4359d25
--- /dev/null
+++ b/support/easylatex/wikiLatexToEasyLatexTables.pl
@@ -0,0 +1,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