-
Notifications
You must be signed in to change notification settings - Fork 71
Convert a tabbed table into a Zim table
sojusnik edited this page Nov 22, 2019
·
3 revisions
Created by Marco Falda
Case: convert a simple tabbed table, for example copied from a browser or LibreOffice Calc, in a Zim table.
- Download and put the script in your "/home/user/bin" directory or wherever you like
- Make it executable.
- Go into Zim Tools --> Custom Tools, and add the script at the bottom of the page with the "%t" command line argument (name the menu item Tabs2table, for example).
- Copy or write a table like this one in a Zim page (spaces are
TAB
s):
A B C
1 2 3
4 5 6
-
Select it
-
Click on the menu Zim Tools --> Tabs2table
-
Refresh the page by switching to another page and then returning to the original one
File "tabs2table.pl":
#!/usr/bin/perl
$i = 0;
foreach $l (split(/\n/, $ARGV[0])) {
chomp($l);
if ($i == 0) {
$h1 = $l;
$h1 =~ s/\t/ | /g;
$h1 = "| $h1 |";
print("$h1\n");
$h2 = $h1;
$h2 =~ s/[^|]/-/g;
$h2 =~ s/-\|/:|/g;
print("$h2\n");
$i++;
}
else {
$l =~ s/\t/ | /g;
$l = "| $l |";
print("$l\n");
}
}