Example #1
0
 def exportColoredHtml(self):
     doc = self.currentDocument()
     name, ext = os.path.splitext(os.path.basename(doc.url().path()))
     if name:
         if ext.lower() == ".html":
             name += "_html"
         name += ".html"
     dir = os.path.dirname(doc.url().toLocalFile())
     if dir:
         name = os.path.join(dir, name)
     filename = QFileDialog.getSaveFileName(self, app.caption(_("Export as HTML")),
         name, "{0} (*.html)".format("HTML Files"))
     if not filename:
         return #cancelled
     number_lines = QSettings().value("source_export/number_lines", False, bool)
     inline_style = QSettings().value("source_export/inline_export", False, bool)
     import highlight2html
     html = highlight2html.html_document(doc, inline=inline_style, number_lines=number_lines)
     try:
         with open(filename, "wb") as f:
             f.write(html.encode('utf-8'))
     except IOError as e:
         msg = _("{message}\n\n{strerror} ({errno})").format(
             message = _("Could not write to: {url}").format(url=filename),
             strerror = e.strerror,
             errno = e.errno)
         QMessageBox.critical(self, app.caption(_("Error")), msg)