eric6/UI/Previewers/PreviewerHTML.py

changeset 7675
7d23e502fe85
parent 7524
282680dae446
child 7684
11e18bf34097
child 7724
a4950a978e8c
equal deleted inserted replaced
7674:60fdbaf3508f 7675:7d23e502fe85
578 """ <a href="http://pypi.python.org/pypi/Sphinx">""" 578 """ <a href="http://pypi.python.org/pypi/Sphinx">"""
579 """this page.</a></p>""" 579 """this page.</a></p>"""
580 """<p>Alternatively you may disable Sphinx usage""" 580 """<p>Alternatively you may disable Sphinx usage"""
581 """ on the Editor, Filehandling configuration page.</p>""") 581 """ on the Editor, Filehandling configuration page.</p>""")
582 582
583 tempDir = tempfile.mkdtemp(prefix='eric-rest-') 583 srcTempDir = tempfile.mkdtemp(prefix="eric-rest-src-")
584 outTempDir = tempfile.mkdtemp(prefix="eric-rest-out-")
585 doctreeTempDir = tempfile.mkdtemp(prefix="eric-rest-doctree-")
584 try: 586 try:
585 filename = 'sphinx_preview' 587 filename = 'sphinx_preview'
586 basePath = os.path.join(tempDir, filename) 588 basePath = os.path.join(srcTempDir, filename)
587 fh = open(basePath + '.rst', 'w', encoding='utf-8') 589 fh = open(basePath + '.rst', 'w', encoding='utf-8')
588 fh.write(text) 590 fh.write(text)
589 fh.close() 591 fh.close()
590 592
591 overrides = {'html_add_permalinks': False, 593 overrides = {'html_add_permalinks': False,
593 'html_title': 'Sphinx preview', 595 'html_title': 'Sphinx preview',
594 'html_use_index': False, 596 'html_use_index': False,
595 'html_use_modindex': False, 597 'html_use_modindex': False,
596 'html_use_smartypants': True, 598 'html_use_smartypants': True,
597 'master_doc': filename} 599 'master_doc': filename}
598 app = Sphinx(srcdir=tempDir, confdir=None, outdir=tempDir, 600 app = Sphinx(srcdir=srcTempDir, confdir=None, outdir=outTempDir,
599 doctreedir=tempDir, buildername='html', 601 doctreedir=doctreeTempDir, buildername='html',
600 confoverrides=overrides, status=None, 602 confoverrides=overrides, status=None,
601 warning=io.StringIO()) 603 warning=io.StringIO())
602 app.build(force_all=True, filenames=None) 604 app.build(force_all=True, filenames=None)
603 605
606 basePath = os.path.join(outTempDir, filename)
604 fh = open(basePath + '.html', 'r', encoding='utf-8') 607 fh = open(basePath + '.html', 'r', encoding='utf-8')
605 html = fh.read() 608 html = fh.read()
606 fh.close() 609 fh.close()
607 finally: 610 finally:
608 shutil.rmtree(tempDir) 611 shutil.rmtree(srcTempDir)
612 shutil.rmtree(outTempDir)
613 shutil.rmtree(doctreeTempDir)
609 614
610 return html 615 return html
611 616
612 def __convertReSTDocutils(self, text, htmlFormat): 617 def __convertReSTDocutils(self, text, htmlFormat):
613 """ 618 """

eric ide

mercurial