eric7/QScintilla/Exporters/ExporterHTML.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8318
962bce857696
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
17 17
18 from PyQt6.QtGui import QFontInfo 18 from PyQt6.QtGui import QFontInfo
19 from PyQt6.QtWidgets import QInputDialog 19 from PyQt6.QtWidgets import QInputDialog
20 from PyQt6.Qsci import QsciScintilla 20 from PyQt6.Qsci import QsciScintilla
21 21
22 from E5Gui import E5MessageBox 22 from E5Gui import EricMessageBox
23 from E5Gui.E5OverrideCursor import E5OverrideCursor 23 from E5Gui.EricOverrideCursor import EricOverrideCursor
24 24
25 from .ExporterBase import ExporterBase 25 from .ExporterBase import ExporterBase
26 26
27 import Preferences 27 import Preferences
28 import Utilities 28 import Utilities
439 if ok: 439 if ok:
440 colorSchemeIndex = colorSchemes.index(colorScheme) 440 colorSchemeIndex = colorSchemes.index(colorScheme)
441 else: 441 else:
442 # light background as default 442 # light background as default
443 colorSchemeIndex = 0 443 colorSchemeIndex = 0
444 with E5OverrideCursor(): 444 with EricOverrideCursor():
445 html = self.__generateFromMarkdown(colorSchemeIndex == 1) 445 html = self.__generateFromMarkdown(colorSchemeIndex == 1)
446 elif ( 446 elif (
447 extension in Preferences.getEditor( 447 extension in Preferences.getEditor(
448 "PreviewRestFileNameExtensions") or 448 "PreviewRestFileNameExtensions") or
449 self.editor.getLanguage().lower() == "restructuredtext" 449 self.editor.getLanguage().lower() == "restructuredtext"
450 ): 450 ):
451 # export ReST to HTML 451 # export ReST to HTML
452 with E5OverrideCursor(): 452 with EricOverrideCursor():
453 html = self.__generateFromReSTDocutils() 453 html = self.__generateFromReSTDocutils()
454 else: 454 else:
455 tabSize = self.editor.getEditorConfig("TabWidth") 455 tabSize = self.editor.getEditorConfig("TabWidth")
456 if tabSize == 0: 456 if tabSize == 0:
457 tabSize = 4 457 tabSize = 4
461 "HTML/OnlyStylesUsed") 461 "HTML/OnlyStylesUsed")
462 titleFullPath = Preferences.getEditorExporter( 462 titleFullPath = Preferences.getEditorExporter(
463 "HTML/FullPathAsTitle") 463 "HTML/FullPathAsTitle")
464 tabs = Preferences.getEditorExporter("HTML/UseTabs") 464 tabs = Preferences.getEditorExporter("HTML/UseTabs")
465 465
466 with E5OverrideCursor(): 466 with EricOverrideCursor():
467 generator = HTMLGenerator(self.editor) 467 generator = HTMLGenerator(self.editor)
468 html = generator.generate( 468 html = generator.generate(
469 tabSize=tabSize, 469 tabSize=tabSize,
470 useTabs=tabs, 470 useTabs=tabs,
471 wysiwyg=wysiwyg, 471 wysiwyg=wysiwyg,
473 onlyStylesUsed=onlyStylesUsed, 473 onlyStylesUsed=onlyStylesUsed,
474 titleFullPath=titleFullPath 474 titleFullPath=titleFullPath
475 ) 475 )
476 476
477 if html: 477 if html:
478 with E5OverrideCursor(), open(filename, "w", encoding="utf-8" 478 with EricOverrideCursor(), open(filename, "w", encoding="utf-8"
479 ) as f: 479 ) as f:
480 try: 480 try:
481 f.write(html) 481 f.write(html)
482 except OSError as err: 482 except OSError as err:
483 E5MessageBox.critical( 483 EricMessageBox.critical(
484 self.editor, 484 self.editor,
485 self.tr("Export source"), 485 self.tr("Export source"),
486 self.tr( 486 self.tr(
487 """<p>The source could not be exported to""" 487 """<p>The source could not be exported to"""
488 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") 488 """ <b>{0}</b>.</p><p>Reason: {1}</p>""")
489 .format(filename, str(err))) 489 .format(filename, str(err)))
490 else: 490 else:
491 E5MessageBox.critical( 491 EricMessageBox.critical(
492 self.editor, 492 self.editor,
493 self.tr("Export source"), 493 self.tr("Export source"),
494 self.tr( 494 self.tr(
495 """<p>The source could not be exported to""" 495 """<p>The source could not be exported to"""
496 """ <b>{0}</b>.</p><p>Reason: No HTML code""" 496 """ <b>{0}</b>.</p><p>Reason: No HTML code"""
511 sys.modules.pop(key) 511 sys.modules.pop(key)
512 512
513 try: 513 try:
514 import docutils.core # __IGNORE_EXCEPTION__ 514 import docutils.core # __IGNORE_EXCEPTION__
515 except ImportError: 515 except ImportError:
516 E5MessageBox.critical( 516 EricMessageBox.critical(
517 self.editor, 517 self.editor,
518 self.tr("Export source"), 518 self.tr("Export source"),
519 self.tr( 519 self.tr(
520 """<p>ReStructuredText export requires the""" 520 """<p>ReStructuredText export requires the"""
521 """ <b>python-docutils</b> package.<br/>Install it with""" 521 """ <b>python-docutils</b> package.<br/>Install it with"""
546 @rtype str 546 @rtype str
547 """ 547 """
548 try: 548 try:
549 import markdown # __IGNORE_EXCEPTION__ 549 import markdown # __IGNORE_EXCEPTION__
550 except ImportError: 550 except ImportError:
551 E5MessageBox.critical( 551 EricMessageBox.critical(
552 self.editor, 552 self.editor,
553 self.tr("Export source"), 553 self.tr("Export source"),
554 self.tr( 554 self.tr(
555 """<p>Markdown export requires the <b>python-markdown""" 555 """<p>Markdown export requires the <b>python-markdown"""
556 """</b> package.<br/>Install it with your package""" 556 """</b> package.<br/>Install it with your package"""

eric ide

mercurial