Skip to content

Instantly share code, notes, and snippets.

@waltervargas
Created April 20, 2014 02:36
Show Gist options
  • Save waltervargas/11103509 to your computer and use it in GitHub Desktop.
Save waltervargas/11103509 to your computer and use it in GitHub Desktop.
Gen _Sidebar from Orgmode file
#!/usr/bin/env perl
my $file = shift || die "Debe indicar el archivo org";
my $base_url = "https://github.com/Covetel/openerp_cooperativas/wiki/";
my @headers = ();
open FILE, "<", $file;
my $title = $file;
$title =~ s/-/ /g;
$title =~ s/\.org//g;
print "*** $title\n";
foreach my $line (<FILE>){
chomp $line;
if ($line =~ /^\*+/){
$line =~ s/\s//; # removing the white spaces
$line =~ s/(\*+)//g; # removing the *
my $link = $1; # capturing the *
$link = $link . ' 1.'; # adding numeric.
$link =~ s/\*/ /g; # replace the * by spaces
my $text = $line;
my $tlink = lc $text;
$tlink =~ s/\s/-/g;
$tlink =~ s/=//g;
$tlink =~ s/\.//g;
$file =~ s/\.org//g;
$link = $link . " [[".$base_url . $file . "#". $tlink ."][". $text ."]]";
$link =~ s/=//g;
print $link . "\n";
}
}
close FILE;
sub walking {
my $el = shift;
$file =~ s/\.org//;
print $link . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment