How to use the nbconvert.HTMLExporter function in nbconvert

To help you get started, we’ve selected a few nbconvert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexisfcote / offline_slides / offlineslides / offlineslides.py View on Github external
def export_to_offline(ipynb_path, slides=True, template_file=None, reveal_scroll=True, no_download=False, verbose=False):
    head, filename = os.path.split(ipynb_path)
    head = './' if head == '' else head

    if slides:
        # Export ipynb to html reveal.js slides
        exporter = SlidesExporter()
        exporter.reveal_theme = 'white'
        exporter.reveal_url_prefix = 'ext/ajax/libs/reveal.js'
        exporter.reveal_scroll=reveal_scroll
    else:
        exporter = HTMLExporter()

    if template_file:
        exporter.template_file = template_file

    if slides:
        suffix = '.slides.offline.html'
    else:
        suffix = '.offline.html'

    new_filename = ''.join(
        (os.path.splitext(filename)[0], suffix))

    if verbose: print('Converting')
    with open(pjoin(head, filename), 'r', encoding='utf-8') as f:
        (body, _) = exporter.from_file(f)
github leo-editor / leo-editor / leo / plugins / viewrendered3.py View on Github external
if body.startswith('{'):
            # Leo 5.7.1: Allow raw JSON.
            s = body
        else:
            url = g.getUrlFromNode(c.p)
            if not url:
                return ''
            if not nbformat:
                return 'can not import nbformt to render url: %r' % url
            try:
                s = urlopen(url).read().decode()
            except Exception:
                return 'url not found: %s' % url
        try:
            nb = nbformat.reads(s, as_version=4)
            e = HTMLExporter()
            (s, junk_resources) = e.from_notebook_node(nb)
        except nbformat.reader.NotJSONError:
            pass # Assume the result is html.
        return s
    #@+node:TomP.20191215195433.63: *4* vr3.update_latex & helper
github pyviz-dev / nbsmoke / nbsmoke / verify.py View on Github external
def export_as_html(filename):
    html_exporter = nbconvert.HTMLExporter()
    html_exporter.template_file = 'basic'
    body, _ = html_exporter.from_filename(filename)
    return body
github OpenHumans / jupyter-gallery / main / views_notebook_details.py View on Github external
def render_notebook(request, notebook_id):
    notebook = SharedNotebook.objects.get(pk=notebook_id)
    format_notebook = nbformat.reads(notebook.notebook_content,
                                     as_version=nbformat.NO_CONVERT)
    html_exporter = nbconvert.HTMLExporter()
    html_exporter.template_file = 'basic'
    # below also removes output of code
    # html_exporter.exclude_code_cell = True
    (body, resources) = html_exporter.from_notebook_node(format_notebook)
    return HttpResponse(body)
github cqcn1991 / Wind-Speed-Analysis / lib / lib_loader.py View on Github external
def output_HTML(read_file, output_file):
    from nbconvert import HTMLExporter
    import codecs
    import nbformat
    exporter = HTMLExporter()
    # read_file is '.ipynb', output_file is '.html'
    output_notebook = nbformat.read(read_file, as_version=4)
    output, resources = exporter.from_notebook_node(output_notebook)
    codecs.open(output_file, 'w', encoding='utf-8').write(output)
github kubeflow / pipelines / backend / src / apiserver / visualization / exporter.py View on Github external
def generate_html_from_notebook(self, nb: NotebookNode) -> Text:
        """Converts a provided NotebookNode to HTML.

        Args:
            nb: NotebookNode that should be converted to HTML.

        Returns:
            HTML from converted NotebookNode as a string.

        """
        # HTML generator and exporter object
        html_exporter = HTMLExporter()
        template_file = "templates/{}.tpl".format(self.template_type.value)
        html_exporter.template_file = str(Path.cwd() / template_file)
        # Output generator
        self.ep.preprocess(nb, {"metadata": {"path": Path.cwd()}}, self.km)
        # Export all html and outputs
        body, _ = html_exporter.from_notebook_node(nb)
        return body
github quiltdata / quilt / lambdas / preview / index.py View on Github external
def extract_ipynb(file_, exclude_output):
    """
    parse and extract ipynb files

    Args:
        file_ - file-like object opened in binary mode (+b)

    Returns:
        html - html version of notebook
        info - unmodified (is also passed in)
    """
    # local import reduces amortized latency, saves memory
    from nbconvert import HTMLExporter
    import nbformat

    html_exporter = HTMLExporter()
    html_exporter.template_file = 'basic'
    html_exporter.exclude_output = exclude_output

    notebook = nbformat.read(file_, 4)
    html, _ = html_exporter.from_notebook_node(notebook)

    return html, {}
github fastai / fastai / fastai / gen_doc / nbdoc.py View on Github external
def md2html(md):
    if nbconvert.__version__ < '5.5.0': return HTMLExporter().markdown2html(md)
    else: return HTMLExporter().markdown2html(defaultdict(lambda: defaultdict(dict)), md)