Convert a tabbed table into a Zim table

Marco Falda edited this page Jan 7, 2018 · 1 revision

Created by Marco Falda

Case: convert a simple tabbed table, for example copied from a browser or LibreOffice Calc, in a Zim table.

  1. Download and put the script in your "/home/user/bin" directory or wherever you like
  2. Make it executable.
  3. 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).

Example

  1. Copy or write a table like this one in a Zim page (spaces are TABs):
A	B	C
1	2	3
4	5	6
  1. Select it

  2. Click on the menu Zim Tools --> Tabs2table

  3. 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");
    }
}
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.