Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def display_as_html(filename, html_outputfile=None):
"""opens the file as html in the web browser"""
import nbconvert
import webbrowser
output = nbconvert.exporters.export(nbconvert.HTMLExporter(), filename)[0]
if html_outputfile == None:
import tempfile
# create temporary file
temp = tempfile.NamedTemporaryFile(mode="w+t", suffix=".html", delete=False)
temp.write(output)
temp.seek(0)
webbrowser.open(temp.name)
else:
with open(html_outputfile, 'w+') as f:
f.write(output)
webbrowser.open(html_outputfile)
if mode == 'python':
data = self.pretty
else:
cleared = (mode == 'cleared')
nb = nbformat.v4.new_notebook()
if self.nbformat_minor is not None:
nb.nbformat_minor = self.nbformat_minor
nb['cells'] = [cell.node(cleared=cleared) for cell in self.cells]
if self.metadata is not None:
nb['metadata'] = self.metadata
if mode == 'html':
if nbconvert is None:
logging.info("nbconvert not available for HTML conversion")
return
(data, resources) = nbconvert.exporters.export(nbconvert.HTMLExporter, nb)
with open(filename, 'w') as f:
if mode in ['cleared', 'full-notebook']:
nbformat.write(nb, f, version=4)
else:
f.write(data)
return {'cmd':'write_complete', 'data':self.name}