390 """ |
390 """ |
391 filename = self._getFileName(self.tr("HTML Files (*.html)")) |
391 filename = self._getFileName(self.tr("HTML Files (*.html)")) |
392 if not filename: |
392 if not filename: |
393 return |
393 return |
394 |
394 |
395 try: |
395 fn = self.editor.getFileName() |
396 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
396 if fn: |
397 QApplication.processEvents() |
397 extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
|
398 else: |
|
399 extension = "" |
|
400 |
|
401 if ( |
|
402 extension in Preferences.getEditor( |
|
403 "PreviewMarkdownFileNameExtensions") or |
|
404 self.editor.getLanguage().lower() == "markdown" |
|
405 ): |
|
406 # export markdown to HTML |
|
407 colorSchemes = [ |
|
408 self.tr("Light Background Color"), |
|
409 self.tr("Dark Background Color"), |
|
410 ] |
|
411 colorScheme, ok = QInputDialog.getItem( |
|
412 None, |
|
413 self.tr("Markdown Export"), |
|
414 self.tr("Select color scheme:"), |
|
415 colorSchemes, |
|
416 0, False) |
|
417 if ok: |
|
418 colorSchemeIndex = colorSchemes.index(colorScheme) |
|
419 else: |
|
420 # light background as default |
|
421 colorSchemeIndex = 0 |
|
422 with E5OverrideCursor(): |
|
423 html = self.__generateFromMarkdown(colorSchemeIndex == 1) |
|
424 elif ( |
|
425 extension in Preferences.getEditor( |
|
426 "PreviewRestFileNameExtensions") or |
|
427 self.editor.getLanguage().lower() == "restructuredtext" |
|
428 ): |
|
429 # export ReST to HTML |
|
430 with E5OverrideCursor(): |
|
431 html = self.__generateFromReSTDocutils() |
|
432 else: |
|
433 tabSize = self.editor.getEditorConfig("TabWidth") |
|
434 if tabSize == 0: |
|
435 tabSize = 4 |
|
436 wysiwyg = Preferences.getEditorExporter("HTML/WYSIWYG") |
|
437 folding = Preferences.getEditorExporter("HTML/Folding") |
|
438 onlyStylesUsed = Preferences.getEditorExporter( |
|
439 "HTML/OnlyStylesUsed") |
|
440 titleFullPath = Preferences.getEditorExporter( |
|
441 "HTML/FullPathAsTitle") |
|
442 tabs = Preferences.getEditorExporter("HTML/UseTabs") |
398 |
443 |
399 fn = self.editor.getFileName() |
444 with E5OverrideCursor(): |
400 if fn: |
|
401 extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
|
402 else: |
|
403 extension = "" |
|
404 |
|
405 if ( |
|
406 extension in Preferences.getEditor( |
|
407 "PreviewMarkdownFileNameExtensions") or |
|
408 self.editor.getLanguage().lower() == "markdown" |
|
409 ): |
|
410 # export markdown to HTML |
|
411 colorSchemes = [ |
|
412 self.tr("Light Background Color"), |
|
413 self.tr("Dark Background Color"), |
|
414 ] |
|
415 QApplication.restoreOverrideCursor() |
|
416 colorScheme, ok = QInputDialog.getItem( |
|
417 None, |
|
418 self.tr("Markdown Export"), |
|
419 self.tr("Select color scheme:"), |
|
420 colorSchemes, |
|
421 0, False) |
|
422 if ok: |
|
423 colorSchemeIndex = colorSchemes.index(colorScheme) |
|
424 else: |
|
425 # light background as default |
|
426 colorSchemeIndex = 0 |
|
427 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
428 QApplication.processEvents() |
|
429 html = self.__generateFromMarkdown(colorSchemeIndex == 1) |
|
430 elif ( |
|
431 extension in Preferences.getEditor( |
|
432 "PreviewRestFileNameExtensions") or |
|
433 self.editor.getLanguage().lower() == "restructuredtext" |
|
434 ): |
|
435 # export ReST to HTML |
|
436 html = self.__generateFromReSTDocutils() |
|
437 else: |
|
438 tabSize = self.editor.getEditorConfig("TabWidth") |
|
439 if tabSize == 0: |
|
440 tabSize = 4 |
|
441 wysiwyg = Preferences.getEditorExporter("HTML/WYSIWYG") |
|
442 folding = Preferences.getEditorExporter("HTML/Folding") |
|
443 onlyStylesUsed = Preferences.getEditorExporter( |
|
444 "HTML/OnlyStylesUsed") |
|
445 titleFullPath = Preferences.getEditorExporter( |
|
446 "HTML/FullPathAsTitle") |
|
447 tabs = Preferences.getEditorExporter("HTML/UseTabs") |
|
448 |
|
449 generator = HTMLGenerator(self.editor) |
445 generator = HTMLGenerator(self.editor) |
450 html = generator.generate( |
446 html = generator.generate( |
451 tabSize=tabSize, |
447 tabSize=tabSize, |
452 useTabs=tabs, |
448 useTabs=tabs, |
453 wysiwyg=wysiwyg, |
449 wysiwyg=wysiwyg, |
454 folding=folding, |
450 folding=folding, |
455 onlyStylesUsed=onlyStylesUsed, |
451 onlyStylesUsed=onlyStylesUsed, |
456 titleFullPath=titleFullPath |
452 titleFullPath=titleFullPath |
457 ) |
453 ) |
458 |
454 |
459 if html: |
455 if html: |
460 try: |
456 try: |
|
457 with E5OverrideCursor(): |
461 f = open(filename, "w", encoding="utf-8") |
458 f = open(filename, "w", encoding="utf-8") |
462 f.write(html) |
459 f.write(html) |
463 f.close() |
460 f.close() |
464 except IOError as err: |
461 except IOError as err: |
465 QApplication.restoreOverrideCursor() |
|
466 E5MessageBox.critical( |
|
467 self.editor, |
|
468 self.tr("Export source"), |
|
469 self.tr( |
|
470 """<p>The source could not be exported to""" |
|
471 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") |
|
472 .format(filename, str(err))) |
|
473 else: |
|
474 QApplication.restoreOverrideCursor() |
|
475 E5MessageBox.critical( |
462 E5MessageBox.critical( |
476 self.editor, |
463 self.editor, |
477 self.tr("Export source"), |
464 self.tr("Export source"), |
478 self.tr( |
465 self.tr( |
479 """<p>The source could not be exported to""" |
466 """<p>The source could not be exported to""" |
480 """ <b>{0}</b>.</p><p>Reason: No HTML code""" |
467 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") |
481 """ generated.</p>""") |
468 .format(filename, str(err))) |
482 .format(filename)) |
469 else: |
483 finally: |
470 E5MessageBox.critical( |
484 QApplication.restoreOverrideCursor() |
471 self.editor, |
|
472 self.tr("Export source"), |
|
473 self.tr( |
|
474 """<p>The source could not be exported to""" |
|
475 """ <b>{0}</b>.</p><p>Reason: No HTML code""" |
|
476 """ generated.</p>""") |
|
477 .format(filename)) |
485 |
478 |
486 def __generateFromReSTDocutils(self): |
479 def __generateFromReSTDocutils(self): |
487 """ |
480 """ |
488 Private method to convert ReST text into HTML using 'docutils'. |
481 Private method to convert ReST text into HTML using 'docutils'. |
489 |
482 |