]> git.phdru.name Git - bookmarks_db.git/blob - Writers/bkmk_whtml.py
Added docstrings, __{version,revision,etc}__ boilerplates.
[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 from bkmk_objects import Writer, BKMK_FORMAT, quote_title
14
15
16 def dump_comment(comment):
17    comment = comment.replace("<BR>\n", "\n")
18    if BKMK_FORMAT == "NETSCAPE":
19       comment = comment.replace("\n", "<BR>\n")
20    return comment
21
22
23 ind_s = " "*4
24
25 class writer_html(Writer):
26    filename = "bookmarks.html"
27
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")
31
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))
36       self._folder(f, 0)
37
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)
43
44    def end_folder(self, f, level):
45       self.outfile.write(ind_s*level + "</DL><p>\n")
46
47    def bookmark(self, b, level):
48       self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s" LAST_VISIT="%s" LAST_MODIFIED="%s"' % (b.href, b.add_date, b.last_visit, b.last_modified))
49       if BKMK_FORMAT == "MOZILLA":
50          if b.keyword: self.outfile.write(' SHORTCUTURL="%s"' % b.keyword)
51          if b.icon_href: self.outfile.write(' ICON_URI="%s"' % b.icon_href)
52          if b.icon: self.outfile.write(' ICON="%s"' % b.icon)
53          if b.charset: self.outfile.write(' LAST_CHARSET="%s"' % b.charset)
54       self.outfile.write('>%s</A>\n' % quote_title(b.name))
55       if b.comment: self.outfile.write('<DD>%s\n' % dump_comment(b.comment))
56
57    def ruler(self, r, level):
58       self.outfile.write(ind_s*(level+1) + "<HR>\n")