eric6/UI/Previewers/PreviewerHTML.py

branch
maintenance
changeset 7824
096b3ebc1409
parent 7737
5371a22cf2aa
parent 7785
9978016560ec
child 7850
e64b178499da
equal deleted inserted replaced
7738:10554f5fac78 7824:096b3ebc1409
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a previewer widget for HTML, Markdown and ReST files. 7 Module implementing a previewer widget for HTML, Markdown and ReST files.
8 """ 8 """
9
10 9
11 import os 10 import os
12 import threading 11 import threading
13 import re 12 import re
14 import shutil 13 import shutil
312 loop.quit() 311 loop.quit()
313 312
314 self.previewView.page().runJavaScript( 313 self.previewView.page().runJavaScript(
315 script, resultCallback) 314 script, resultCallback)
316 315
317 loop.exec_() 316 loop.exec()
318 return resultDict["res"] 317 return resultDict["res"]
319 318
320 319
321 class PreviewProcessingThread(QThread): 320 class PreviewProcessingThread(QThread):
322 """ 321 """
496 incFile = Utilities.normjoinpath(baseDir, incMatch.group(2)) 495 incFile = Utilities.normjoinpath(baseDir, incMatch.group(2))
497 else: 496 else:
498 incFile = "" 497 incFile = ""
499 if os.path.exists(incFile): 498 if os.path.exists(incFile):
500 try: 499 try:
501 f = open(incFile, "r") 500 with open(incFile, "r") as f:
502 incTxt = f.read() 501 incTxt = f.read()
503 f.close()
504 except (IOError, OSError): 502 except (IOError, OSError):
505 # remove SSI include 503 # remove SSI include
506 incTxt = "" 504 incTxt = ""
507 else: 505 else:
508 # remove SSI include 506 # remove SSI include
584 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-") 582 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-")
585 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-") 583 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-")
586 try: 584 try:
587 filename = 'sphinx_preview' 585 filename = 'sphinx_preview'
588 basePath = os.path.join(srcTempDir, filename) 586 basePath = os.path.join(srcTempDir, filename)
589 fh = open(basePath + '.rst', 'w', encoding='utf-8') 587 with open(basePath + '.rst', 'w', encoding='utf-8') as fh:
590 fh.write(text) 588 fh.write(text)
591 fh.close() 589
592
593 overrides = {'html_add_permalinks': False, 590 overrides = {'html_add_permalinks': False,
594 'html_copy_source': False, 591 'html_copy_source': False,
595 'html_title': 'Sphinx preview', 592 'html_title': 'Sphinx preview',
596 'html_use_index': False, 593 'html_use_index': False,
597 'html_use_modindex': False, 594 'html_use_modindex': False,
602 confoverrides=overrides, status=None, 599 confoverrides=overrides, status=None,
603 warning=io.StringIO()) 600 warning=io.StringIO())
604 app.build(force_all=True, filenames=None) 601 app.build(force_all=True, filenames=None)
605 602
606 basePath = os.path.join(outTempDir, filename) 603 basePath = os.path.join(outTempDir, filename)
607 fh = open(basePath + '.html', 'r', encoding='utf-8') 604 with open(basePath + '.html', 'r', encoding='utf-8') as fh:
608 html = fh.read() 605 html = fh.read()
609 fh.close()
610 finally: 606 finally:
611 shutil.rmtree(srcTempDir) 607 shutil.rmtree(srcTempDir)
612 shutil.rmtree(outTempDir) 608 shutil.rmtree(outTempDir)
613 shutil.rmtree(doctreeTempDir) 609 shutil.rmtree(doctreeTempDir)
614 610

eric ide

mercurial