]> git.phdru.name Git - bookmarks_db.git/blob - Writers/bkmk_whtml.py
last_visit could be None.
[bookmarks_db.git] / Writers / bkmk_whtml.py
1 """Convert a bkmk database back to bookmarks.html
2
3 This file is a part of Bookmarks database and Internet robot.
4 """
5
6 __version__ = "$Revision$"[11:-2]
7 __revision__ = "$Id$"[5:-2]
8 __date__ = "$Date$"[7:-2]
9 __author__ = "Oleg Broytman <phd@phdru.name>"
10 __copyright__ = "Copyright (C) 2000-2011 PhiloSoft Design"
11 __license__ = "GNU GPL"
12
13 __all__ = ['writer_html']
14
15
16 from bkmk_objects import Writer, BKMK_FORMAT, quote_title
17
18
19 def dump_comment(comment):
20    comment = comment.replace("<BR>\n", "\n")
21    if BKMK_FORMAT == "NETSCAPE":
22       comment = comment.replace("\n", "<BR>\n")
23    return comment
24
25
26 ind_s = " "*4
27
28 class writer_html(Writer):
29    filename = "bookmarks.html"
30
31    def _folder(self, f, level):
32       if f.comment: self.outfile.write('<DD>%s\n' % dump_comment(f.comment))
33       self.outfile.write(ind_s*level + "<DL><p>\n")
34
35    def root_folder(self, f):
36       self.outfile.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n")
37       self.outfile.write(f.header + "\n")
38       self.outfile.write('<H1>%s</H1>\n\n' % quote_title(f.name))
39       self._folder(f, 0)
40
41    def start_folder(self, f, level):
42       self.outfile.write(ind_s*level + '<DT><H3 ADD_DATE="%s"' % f.add_date)
43       if (BKMK_FORMAT == "MOZILLA") and f.last_modified: self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
44       self.outfile.write('>%s</H3>\n' % quote_title(f.name))
45       self._folder(f, level)
46
47    def end_folder(self, f, level):
48       self.outfile.write(ind_s*level + "</DL><p>\n")
49
50    def bookmark(self, b, level):
51       self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href, b.add_date))
52       if b.last_visit: self.outfile.write('LAST_VISIT="%s"' % b.last_visit)
53       self.outfile.write('LAST_MODIFIED="%s"' % b.last_modified)
54       if BKMK_FORMAT == "MOZILLA":
55          if b.keyword: self.outfile.write(' SHORTCUTURL="%s"' % b.keyword)
56          if b.icon_href: self.outfile.write(' ICON_URI="%s"' % b.icon_href)
57          if b.icon: self.outfile.write(' ICON="%s"' % b.icon)
58          if b.charset: self.outfile.write(' LAST_CHARSET="%s"' % b.charset)
59       self.outfile.write('>%s</A>\n' % quote_title(b.name))
60       if b.comment: self.outfile.write('<DD>%s\n' % dump_comment(b.comment))
61
62    def ruler(self, r, level):
63       self.outfile.write(ind_s*(level+1) + "<HR>\n")