eric6/QScintilla/Exporters/ExporterHTML.py

changeset 8205
4a0f1f896341
parent 7960
e8fc383322f7
child 8243
cc717c2ae956
equal deleted inserted replaced
8204:fd477cded1c1 8205:4a0f1f896341
25 25
26 import Preferences 26 import Preferences
27 import Utilities 27 import Utilities
28 28
29 29
30 class HTMLGenerator(object): 30 class HTMLGenerator:
31 """ 31 """
32 Class implementing an HTML generator for exporting source code. 32 Class implementing an HTML generator for exporting source code.
33 """ 33 """
34 def __init__(self, editor): 34 def __init__(self, editor):
35 """ 35 """
186 html += ' color: {0};\n'.format(colour.name()) 186 html += ' color: {0};\n'.format(colour.name())
187 if wysiwyg: 187 if wysiwyg:
188 html += ' font-size: {0:d}pt;\n'.format( 188 html += ' font-size: {0:d}pt;\n'.format(
189 QFontInfo(font).pointSize()) 189 QFontInfo(font).pointSize())
190 html += '}\n' 190 html += '}\n'
191 # __IGNORE_WARNING_Y113__
191 else: 192 else:
192 styleIsUsed[istyle] = False 193 styleIsUsed[istyle] = False
193 istyle += 1 194 istyle += 1
194 else: 195 else:
195 colour = self.editor.color() 196 colour = self.editor.color()
413 filename = self._getFileName(self.tr("HTML Files (*.html)")) 414 filename = self._getFileName(self.tr("HTML Files (*.html)"))
414 if not filename: 415 if not filename:
415 return 416 return
416 417
417 fn = self.editor.getFileName() 418 fn = self.editor.getFileName()
418 if fn: 419 extension = os.path.normcase(os.path.splitext(fn)[1][1:]) if fn else ""
419 extension = os.path.normcase(os.path.splitext(fn)[1][1:])
420 else:
421 extension = ""
422 420
423 if ( 421 if (
424 extension in Preferences.getEditor( 422 extension in Preferences.getEditor(
425 "PreviewMarkdownFileNameExtensions") or 423 "PreviewMarkdownFileNameExtensions") or
426 self.editor.getLanguage().lower() == "markdown" 424 self.editor.getLanguage().lower() == "markdown"
473 onlyStylesUsed=onlyStylesUsed, 471 onlyStylesUsed=onlyStylesUsed,
474 titleFullPath=titleFullPath 472 titleFullPath=titleFullPath
475 ) 473 )
476 474
477 if html: 475 if html:
478 try: 476 with E5OverrideCursor(), open(filename, "w", encoding="utf-8"
479 with E5OverrideCursor(): 477 ) as f:
480 with open(filename, "w", encoding="utf-8") as f: 478 try:
481 f.write(html) 479 f.write(html)
482 except OSError as err: 480 except OSError as err:
483 E5MessageBox.critical( 481 E5MessageBox.critical(
484 self.editor, 482 self.editor,
485 self.tr("Export source"), 483 self.tr("Export source"),
486 self.tr( 484 self.tr(
487 """<p>The source could not be exported to""" 485 """<p>The source could not be exported to"""
488 """ <b>{0}</b>.</p><p>Reason: {1}</p>""") 486 """ <b>{0}</b>.</p><p>Reason: {1}</p>""")
489 .format(filename, str(err))) 487 .format(filename, str(err)))
490 else: 488 else:
491 E5MessageBox.critical( 489 E5MessageBox.critical(
492 self.editor, 490 self.editor,
493 self.tr("Export source"), 491 self.tr("Export source"),
494 self.tr( 492 self.tr(
566 extensions = [] 564 extensions = []
567 565
568 text = self.editor.text() 566 text = self.editor.text()
569 567
570 mermaidNeeded = False 568 mermaidNeeded = False
571 if Preferences.getEditor("PreviewMarkdownMermaid"): 569 if (
572 if MarkdownExtensions.MermaidRegexFullText.search(text): 570 Preferences.getEditor("PreviewMarkdownMermaid") and
573 extensions.append(MarkdownExtensions.MermaidExtension()) 571 MarkdownExtensions.MermaidRegexFullText.search(text)
574 mermaidNeeded = True 572 ):
573 extensions.append(MarkdownExtensions.MermaidExtension())
574 mermaidNeeded = True
575 575
576 if Preferences.getEditor("PreviewMarkdownNLtoBR"): 576 if Preferences.getEditor("PreviewMarkdownNLtoBR"):
577 extensions.append('nl2br') 577 extensions.append('nl2br')
578 578
579 pyMdown = False 579 pyMdown = False

eric ide

mercurial