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, OSError) as err: QMessageBox.warning( self, app.caption(_("Error")), _("Can't write to destination:\n\n{url}\n\n{error}").format( url=filename, error=err))
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)
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"))[0] if not filename: return #cancelled s = QSettings() s.beginGroup("source_export") number_lines = s.value("number_lines", False, bool) inline_style = s.value("inline_export", False, bool) wrap_tag = s.value("wrap_tag", "pre", str) wrap_attrib = s.value("wrap_attrib", "id", str) wrap_attrib_name = s.value("wrap_attrib_name", "document", str) import highlight2html html = highlight2html.html_document(doc, inline=inline_style, number_lines=number_lines, wrap_tag=wrap_tag, wrap_attrib=wrap_attrib, wrap_attrib_name=wrap_attrib_name) 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)