]> git.phdru.name Git - bookmarks_db.git/blobdiff - Writers/bkmk_whtml.py
Fix: do not write LAST_MODIFIED is it's None
[bookmarks_db.git] / Writers / bkmk_whtml.py
index 775d336fea0c4060a35090c307f8be12cfe20311..caf374737b29f3ea873cbe0c9599c931b7d233da 100644 (file)
@@ -1,29 +1,27 @@
-"""
-   Convert a bkmk database back to bookmarks.html
+"""Convert a bkmk database back to bookmarks.html
 
-   Written by BroytMann. Copyright (C) 2000-2007 PhiloSoft Design
+This file is a part of Bookmarks database and Internet robot.
 """
 
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__license__ = "GNU GPL"
+
+__all__ = ['writer_html']
+
 
-import os
-MZFORMAT = os.environ.has_key("BKMK_MZFORMAT")
-if MZFORMAT:
-   NSFORMAT = False
-else:
-   NSFORMAT = os.environ.has_key("BKMK_NSFORMAT")
+from m_lib.defenc import default_encoding
+from bkmk_objects import Writer, BKMK_FORMAT, quote_title
 
 
 def dump_comment(comment):
    comment = comment.replace("<BR>\n", "\n")
-   if NSFORMAT:
+   if BKMK_FORMAT == "NETSCAPE":
       comment = comment.replace("\n", "<BR>\n")
    return comment
 
-
 ind_s = " "*4
 
-from bkmk_objects import Writer
-
 class writer_html(Writer):
    filename = "bookmarks.html"
 
@@ -34,25 +32,29 @@ class writer_html(Writer):
    def root_folder(self, f):
       self.outfile.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n")
       self.outfile.write(f.header + "\n")
-      self.outfile.write('<H1>%s</H1>\n\n' % f.name)
+      self.outfile.write('<H1>%s</H1>\n\n' % quote_title(f.name))
       self._folder(f, 0)
 
    def start_folder(self, f, level):
       self.outfile.write(ind_s*level + '<DT><H3 ADD_DATE="%s"' % f.add_date)
-      if MZFORMAT and f.last_modified: self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
-      self.outfile.write('>%s</H3>\n' % f.name)
+      if (BKMK_FORMAT == "MOZILLA") and f.last_modified: self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
+      self.outfile.write('>%s</H3>\n' % quote_title(f.name))
       self._folder(f, level)
 
    def end_folder(self, f, level):
       self.outfile.write(ind_s*level + "</DL><p>\n")
 
    def bookmark(self, b, level):
-      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))
-      if MZFORMAT:
+      self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href, b.add_date))
+      if b.last_visit: self.outfile.write(' LAST_VISIT="%s"' % b.last_visit)
+      if b.last_modified:
+         self.outfile.write(' LAST_MODIFIED="%s"' % b.last_modified)
+      if BKMK_FORMAT == "MOZILLA":
          if b.keyword: self.outfile.write(' SHORTCUTURL="%s"' % b.keyword)
+         if b.icon_href: self.outfile.write(' ICON_URI="%s"' % b.icon_href)
          if b.icon: self.outfile.write(' ICON="%s"' % b.icon)
          if b.charset: self.outfile.write(' LAST_CHARSET="%s"' % b.charset)
-      self.outfile.write('>%s</A>\n' % b.name)
+      self.outfile.write('>%s</A>\n' % quote_title(b.name))
       if b.comment: self.outfile.write('<DD>%s\n' % dump_comment(b.comment))
 
    def ruler(self, r, level):