def to_html(self): cb_name = self.nb_buffer.name.split('/')[-1] notebook_name = cb_name.split('.')[0] self.write_buffer() html_exporter = HTMLExporter(config=self.c) html_exporter.template_file = 'full' body, resources = html_exporter.from_filename(cb_name) self.writer.write(body, resources, notebook_name = notebook_name)
else: params = {} _log.info('executing notebook') pm.execute_notebook(os.fspath(nbfile), os.fspath(tmp_nbf), params) _log.info('loading %s', tmp_nbf) with tmp_nbf.open() as nbf: nb = nbformat.read(nbf, as_version=4) if args['--output']: htmlfile = Path(args['--output']) else: htmlfile = nbfile.with_suffix('.html') _log.info('saving HTML %s', htmlfile) htmle = HTMLExporter() htmle.template_file = 'full' (body, resources) = htmle.from_notebook_node(nb) htmlfile.write_text(body) if args['--overwrite']: _log.info('overwriting %s', nbfile) if nbfile.exists(): nbfile.unlink() tmp_nbf.rename(nbfile) finally: if tmp_nbf.exists(): tmp_nbf.unlink()