]> git.phdru.name Git - bookmarks_db.git/blob - Writers/bkmk_whtml.py
Split hrefs into domain and path components; recode only domain.
[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 m_lib.defenc import default_encoding
17 from bkmk_objects import Writer, BKMK_FORMAT, quote_title
18
19
20 def dump_comment(comment):
21    comment = comment.replace("<BR>\n", "\n")
22    if BKMK_FORMAT == "NETSCAPE":
23       comment = comment.replace("\n", "<BR>\n")
24    return comment
25
26
27 ind_s = " "*4
28
29 class writer_html(Writer):
30    filename = "bookmarks.html"
31
32    def _folder(self, f, level):
33       if f.comment: self.outfile.write('<DD>%s\n' % dump_comment(f.comment))
34       self.outfile.write(ind_s*level + "<DL><p>\n")
35
36    def root_folder(self, f):
37       self.outfile.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n")
38       self.outfile.write(f.header + "\n")
39       self.outfile.write('<H1>%s</H1>\n\n' % quote_title(f.name))
40       self._folder(f, 0)
41
42    def start_folder(self, f, level):
43       self.outfile.write(ind_s*level + '<DT><H3 ADD_DATE="%s"' % f.add_date)
44       if (BKMK_FORMAT == "MOZILLA") and f.last_modified: self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
45       self.outfile.write('>%s</H3>\n' % quote_title(f.name))
46       self._folder(f, level)
47
48    def end_folder(self, f, level):
49       self.outfile.write(ind_s*level + "</DL><p>\n")
50
51    def bookmark(self, b, level):
52       self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href, b.add_date))
53       if b.last_visit: self.outfile.write(' LAST_VISIT="%s"' % b.last_visit)
54       self.outfile.write(' LAST_MODIFIED="%s"' % b.last_modified)
55       if BKMK_FORMAT == "MOZILLA":
56          if b.keyword: self.outfile.write(' SHORTCUTURL="%s"' % b.keyword)
57          if b.icon_href: self.outfile.write(' ICON_URI="%s"' % b.icon_href)
58          if b.icon: self.outfile.write(' ICON="%s"' % b.icon)
59          if b.charset: self.outfile.write(' LAST_CHARSET="%s"' % b.charset)
60       self.outfile.write('>%s</A>\n' % quote_title(b.name))
61       if b.comment: self.outfile.write('<DD>%s\n' % dump_comment(b.comment))
62
63    def ruler(self, r, level):
64       self.outfile.write(ind_s*(level+1) + "<HR>\n")