eric6/UI/Previewers/PreviewerHTML.py

changeset 7785
9978016560ec
parent 7781
607a6098cb44
child 7824
096b3ebc1409
child 7836
2f0d208b8137
equal deleted inserted replaced
7784:3257703e10c5 7785:9978016560ec
495 incFile = Utilities.normjoinpath(baseDir, incMatch.group(2)) 495 incFile = Utilities.normjoinpath(baseDir, incMatch.group(2))
496 else: 496 else:
497 incFile = "" 497 incFile = ""
498 if os.path.exists(incFile): 498 if os.path.exists(incFile):
499 try: 499 try:
500 f = open(incFile, "r") 500 with open(incFile, "r") as f:
501 incTxt = f.read() 501 incTxt = f.read()
502 f.close()
503 except (IOError, OSError): 502 except (IOError, OSError):
504 # remove SSI include 503 # remove SSI include
505 incTxt = "" 504 incTxt = ""
506 else: 505 else:
507 # remove SSI include 506 # remove SSI include
583 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-") 582 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-")
584 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-") 583 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-")
585 try: 584 try:
586 filename = 'sphinx_preview' 585 filename = 'sphinx_preview'
587 basePath = os.path.join(srcTempDir, filename) 586 basePath = os.path.join(srcTempDir, filename)
588 fh = open(basePath + '.rst', 'w', encoding='utf-8') 587 with open(basePath + '.rst', 'w', encoding='utf-8') as fh:
589 fh.write(text) 588 fh.write(text)
590 fh.close() 589
591
592 overrides = {'html_add_permalinks': False, 590 overrides = {'html_add_permalinks': False,
593 'html_copy_source': False, 591 'html_copy_source': False,
594 'html_title': 'Sphinx preview', 592 'html_title': 'Sphinx preview',
595 'html_use_index': False, 593 'html_use_index': False,
596 'html_use_modindex': False, 594 'html_use_modindex': False,
601 confoverrides=overrides, status=None, 599 confoverrides=overrides, status=None,
602 warning=io.StringIO()) 600 warning=io.StringIO())
603 app.build(force_all=True, filenames=None) 601 app.build(force_all=True, filenames=None)
604 602
605 basePath = os.path.join(outTempDir, filename) 603 basePath = os.path.join(outTempDir, filename)
606 fh = open(basePath + '.html', 'r', encoding='utf-8') 604 with open(basePath + '.html', 'r', encoding='utf-8') as fh:
607 html = fh.read() 605 html = fh.read()
608 fh.close()
609 finally: 606 finally:
610 shutil.rmtree(srcTempDir) 607 shutil.rmtree(srcTempDir)
611 shutil.rmtree(outTempDir) 608 shutil.rmtree(outTempDir)
612 shutil.rmtree(doctreeTempDir) 609 shutil.rmtree(doctreeTempDir)
613 610

eric ide

mercurial