#!/usr/bin/perl -w
# Copywrite Nick Warne 14/05/2016
# Licence: Public Domain 
# Firefox bookmarks.html converter for Dillo bm.txt
# 
# To use:  place this script in the same directory as your
# saved Firefox bookmarks.html file, and run 'perl ff_to_bm.pl'
# Output to stdout:  when happy, add the results to your bm.txt

my @urls;
my $line;
my $name;

# Assume Dillo user already has :s0: bookmark section
# This can be changed to suit (i.e. if you have :s0: and :s1:, set this to 1)
my $count = 0;

open (BM, "< bookmarks.html");
@urls= <BM>;
close (BM);

foreach $line (@urls) {
$line =~ tr/ //ds;

  if ($line =~ /\<\/H3\>/i) {
     $count = $count+1;
     $line =~ s/.*\<.*\"\>//gi;
     $line =~ s/\<\/H3\>//gi;
     $line = ":s".$count.": ".$line;;
     print $line;
  }
 
 if ($line =~ /HREF/) {
     $line =~ s/.*HREF\=\"//gi;
     $name = $line;
     $line =~ s/\"ADD.*//gi;
     chomp($line);
     $name =~ s/.*\"\>//gi;
     $name =~ s/\<\/A\>//gi;
     $line = "s".$count." ".$line." ".$name;
     print $line;
 }

}
