How to use the nbconvert.exporters.html.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 choderalab / yank / docs / sphinxext / notebook_sphinxext.py View on Github external
def nb_to_html(nb_path):
    """convert notebook to html"""
    exporter = html.HTMLExporter(template_file='full')
    output, resources = exporter.from_filename(nb_path)
    header = output.split('', 1)[1].split('',1)[0]
    body = output.split('', 1)[1].split('',1)[0]

    # http://imgur.com/eR9bMRH
    header = header.replace('
github voila-dashboards / voila / voila / exporter.py View on Github external
class VoilaMarkdownRenderer(IPythonRenderer):
    """Custom markdown renderer that inlines images"""

    def image(self, src, title, text):
        contents_manager = self.options['contents_manager']
        if contents_manager.file_exists(src):
            content = contents_manager.get(src, format='base64')
            data = content['content'].replace('\n', '')  # remove the newline
            mime_type, encoding = mimetypes.guess_type(src)
            src = 'data:{mime_type};base64,{data}'.format(mime_type=mime_type, data=data)
        return super(VoilaMarkdownRenderer, self).image(src, title, text)


class VoilaExporter(HTMLExporter):
    """Custom HTMLExporter that inlines the images using VoilaMarkdownRenderer"""

    markdown_renderer_class = traitlets.Type('mistune.Renderer').tag(config=True)

    # The voila exporter overrides the markdown renderer from the HTMLExporter
    # to inline images.
    @contextfilter
    def markdown2html(self, context, source):
        cell = context['cell']
        attachments = cell.get('attachments', {})
        cls = self.markdown_renderer_class
        renderer = cls(escape=False, attachments=attachments,
                       contents_manager=self.contents_manager,
                       anchor_link_text=self.anchor_link_text)
        return MarkdownWithMath(renderer=renderer).render(source)
github Metatab / metatab / metatab / jupyter / exporters.py View on Github external
def add_html_doc(self, nb, resources):
        html_exp = HTMLExporter(config=self.config, template_file='hide_input_html.tpl')

        (html_full_body, _) = html_exp.from_notebook_node(nb)

        resources['outputs']['documentation.html'] = html_full_body.encode('utf-8')
github Anaconda-Platform / nbbrowserpdf / nbbrowserpdf / exporters / pdf.py View on Github external
import os
import shutil
import subprocess
import sys

from ipython_genutils.tempdir import TemporaryWorkingDirectory
import nbformat

from nbconvert.exporters.html import HTMLExporter


class BrowserPDFExporter(HTMLExporter):
    """ An exporter that generates PDF with a headless browser.
        Heavily influenced by the nbconvert LaTeX-based PDFExporter.
    """
    def pdf_capture_args(self):
        """ extra arguments to pass to pdf_capture... such as
            --capture-server-class
        """
        return []

    def from_notebook_node(self, nb, resources=None, **kw):
        """ Generate a PDF from a given parsed notebook node
        """
        output, resources = super(BrowserPDFExporter, self).from_notebook_node(
            nb, resources=resources, **kw
        )
github Metatab / metatab / metatab / jupyter / exporters.py View on Github external
def add_basic_html_doc(self, nb, resources):
        html_exp = HTMLExporter(config=self.config, template_file='hide_input_html_basic.tpl')

        (html_basic_body, _) = html_exp.from_notebook_node(nb)

        resources['outputs']['html_basic_body.html'] = html_basic_body.encode('utf-8')
github onecodex / onecodex / onecodex / notebooks / exporters.py View on Github external
img
                    )
                }
            elif "image/png" in out["data"]:
                out["data"] = {"text/html": '
github csiro-scientific-computing / NotebookDiff / notebookdiff / notebook_diff.py View on Github external
CellComparator(cell, check_modified=check_modified)
            for cell in before_cells
        ]
        after_comps = [
            CellComparator(cell, check_modified=check_modified)
            for cell in after_cells
        ]
        diff_result = Diff.diff(
            before_comps,
            after_comps,
            check_modified=check_modified
        )
        return diff_result
        
        
class Exporter(HTMLExporter):
    def __init__(self, *args, **kwargs):
        super(Exporter, self).__init__(*args, **kwargs)
        self.register_preprocessor(ExporterPreprocessor, True)
        
    def _template_file_default(self):
        return 'nbdiff'
        
    def _template_path_default(self):
        return [os.path.dirname(os.path.abspath(__file__))]
        
class ExporterPreprocessor(Preprocessor):
    def preprocess(self, nb, resources):
        resources['metadata']['name'] = "Diff"
        return nb, resources
        
class Diff():
github ipython-contrib / jupyter_contrib_nbextensions / src / jupyter_contrib_nbextensions / nbconvert_support / toc2.py View on Github external
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------

from nbconvert.exporters.html import HTMLExporter
from traitlets.config import Config


# -----------------------------------------------------------------------------
# Classes
# -----------------------------------------------------------------------------


class TocExporter(HTMLExporter):
    """
    :mod:`nbconvert` HTMLExporter which embeds the toc2 nbextension.

    Export table of contents nbextension functionality to html. The idea is to
    link a relevant part of the javascript nbextension and the css, and add a
    small script in the html file.

    Example usage::

        jupyter nbconvert --to html_toc FILE.ipynb
    """
    
    export_from_notebook = "HTML + ToC"


    def _file_extension_default(self):