Re: bookmarks
| Newsgroups | gmane.comp.web.elinks.user |
|---|---|
| Message-ID | <[email protected]> |
Incase anyone is still listening and is interested I have written a perl script that will convert firefox bookmarks to elinks (non xml) bookmarks. I imagine firefox saves bookmarks the same regardless of which OS you use (I may be wrong). The script finds the firefox bookmarks file (works on linux) otherwise use --i='input_bookmarks' to specify. It will also write the elinks bookmarks file to its standard place, otherwise use --o='output_bookmarks' saving the current bookmarks file as bookmarks.conf If I find the motivation I may do the same for safari bookmarks too On 06/05/2008, David Collins <[email protected]> wrote: > Hi, > > I have been using elinks for a couple of weeks now and I love it. It > seems to have a few small things that other browsers don't have but > you really miss having! Such as session save. > > I have been fine not using my bookmarks up until now, and when I have > needed something I have opened up my firefox bookmarks as an html > page. I was wondering if anyone has written a script that will put the > firefox bookmarks into elinks (non xml) bookmarks format? > > David > _______________________________________________ elinks-users mailing list [email protected] http://linuxfromscratch.org/mailman/listinfo/elinks-users
firefox2elinks.pl
(application/x-perl, 2.2 KB)
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
##
## Convert a firefox bookmarks.html file into a elinks native bookmark file
## USAGE:
## firefox2elinks.pl [--i=infile] [--o=outfile]
##
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##
## firefox bookmark format
##
##
## <DL> enter folder
## <DT> entry - URL(<A HREF>), folder(<H3>)
## </DL> exit folder
##
##
##
## elinks bookmark format
##
## folder \t \t N \t F - N is level of folder root N=0, folder in folder N=1
## bookmark name \t URL \t M - M is level from root M=N+1, root bm M=1, in 1 folder M=2, 2; M=2
##
use strict;
use warnings;
use Getopt::Long;
use File::Copy;
## find standard elinks/firefox bookmarks to use if
## nothing is specified
my $inputfile = `find $ENV{HOME}/.mozilla/firefox -name 'bookmarks.html'`;
chomp($inputfile);
my $outputfile = "$ENV{HOME}/.elinks/bookmarks";
my $argret=GetOptions(
"i=s" => \$inputfile,
"o=s" => \$outputfile,
);
print "\nConverting firefox bookmarks \"$inputfile\"\n".
"\tto elinks standard bookmarks \"$outputfile\".....\n";
my $start_of_bm = 1;
my $folder_counter = 0;
## copy current elinks.conf file if it exists
if(-e $outputfile) {
print ".... Copying \"$outputfile\" to \"$outputfile.orig\"....\n";
copy($outputfile, "$outputfile.orig")
or die "Cannot copy $outputfile\n";
}
## open firefox bm to read and elinks bm to write to
open(IN, "$inputfile") or die "cannot open $inputfile: $!";
open(OUT, ">$outputfile") or die "cannot open $outputfile: $!";
while(<IN>) {
if(/<HR>/) { $start_of_bm = 0; }
## don't start parsing until past the horizontal rule
if(!$start_of_bm) {
## count folders that are moved into and out of
if(/<DL>/) { $folder_counter++; }
if(/<\/DL>/) { $folder_counter--; }
## match folder title
if (/<H[0-9]/) {
s/.*?<H[0-9].*?>(.*?)<//;
print OUT "$1\t\t${folder_counter}\tF\n";
}
## match bookmark url
if (/<A HREF/) {
s/.*?<A HREF="(.*?)".*?>(.*?)<//;
print OUT "$2\t$1\t${folder_counter}\n";
}
}
}
## close opened files
close(IN);
close(OUT);
print "\tConversion complete\n\n";