1 """Convert a bkmk database back to bookmarks.html
3 This file is a part of Bookmarks database and Internet robot.
6 __author__ = "Oleg Broytman <phd@phdru.name>"
7 __copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
8 __license__ = "GNU GPL"
10 __all__ = ['writer_html']
13 from m_lib.defenc import default_encoding
14 from bkmk_objects import Writer, BKMK_FORMAT, quote_title
17 def dump_comment(comment):
18 comment = comment.replace("<BR>\n", "\n")
19 if BKMK_FORMAT == "NETSCAPE":
20 comment = comment.replace("\n", "<BR>\n")
25 class writer_html(Writer):
26 filename = "bookmarks.html"
28 def _folder(self, f, level):
29 if f.comment: self.outfile.write('<DD>%s\n' % dump_comment(f.comment))
30 self.outfile.write(ind_s*level + "<DL><p>\n")
32 def root_folder(self, f):
33 self.outfile.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n")
34 self.outfile.write(f.header + "\n")
35 self.outfile.write('<H1>%s</H1>\n\n' % quote_title(f.name))
38 def start_folder(self, f, level):
39 self.outfile.write(ind_s*level + '<DT><H3 ADD_DATE="%s"' % f.add_date)
40 if (BKMK_FORMAT == "MOZILLA") and f.last_modified: self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
41 self.outfile.write('>%s</H3>\n' % quote_title(f.name))
42 self._folder(f, level)
44 def end_folder(self, f, level):
45 self.outfile.write(ind_s*level + "</DL><p>\n")
47 def bookmark(self, b, level):
48 self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href, b.add_date))
49 if b.last_visit: self.outfile.write(' LAST_VISIT="%s"' % b.last_visit)
50 self.outfile.write(' LAST_MODIFIED="%s"' % b.last_modified)
51 if BKMK_FORMAT == "MOZILLA":
52 if b.keyword: self.outfile.write(' SHORTCUTURL="%s"' % b.keyword)
53 if b.icon_href: self.outfile.write(' ICON_URI="%s"' % b.icon_href)
54 if b.icon: self.outfile.write(' ICON="%s"' % b.icon)
55 if b.charset: self.outfile.write(' LAST_CHARSET="%s"' % b.charset)
56 self.outfile.write('>%s</A>\n' % quote_title(b.name))
57 if b.comment: self.outfile.write('<DD>%s\n' % dump_comment(b.comment))
59 def ruler(self, r, level):
60 self.outfile.write(ind_s*(level+1) + "<HR>\n")