Exemple #1
0
def get_html_from_filepath(filepath,
                           template=None,
                           start=0,
                           end=None,
                           no_prompts=False):
    """Convert ipython notebook to html
    Return: html content of the converted notebook
    """
    if template is None:
        template = 'basic'

    config = Config({
        'CSSHTMLHeaderTransformer': {
            'enabled': True,
            'highlight_class': '.highlight-ipynb'
        },
        'SubCell': {
            'enabled': True,
            'start': start,
            'end': end
        }
    })
    exporter = HTMLExporter(config=config,
                            template_file=template,
                            filters={'highlight2html': custom_highlighter},
                            preprocessors=[SubCell])

    # Remove all the input and output prompts from the exported HTML, this extends the width of
    # all cells,, not just the input and output cells.
    if no_prompts:
        exporter.exclude_input_prompt = True
        exporter.exclude_output_prompt = True

    content, info = exporter.from_filename(filepath)

    if BeautifulSoup:
        soup = BeautifulSoup(content, 'html.parser')
        for i in soup.findAll('div', {'class': 'input'}):
            if i.findChildren()[1].find(text='#ignore') is not None:
                i.extract()
        content = soup.decode(formatter=None)

    return content, info