In [9]:
from IPython.nbformat import current as nbformat
from pygments.formatters import HtmlFormatter
from IPython.nbconvert.exporters import HTMLExporter
from IPython.config import Config
from IPython.nbconvert.filters.highlight import _pygments_highlight
from IPython.display import clear_output, display, HTML
In [10]:
with open('highchart.ipynb') as f:
double11_notebook = nbformat.reads_json(f.read())
In [11]:
def my_highlight(source, language='ipython'):
formatter = HtmlFormatter(cssclass='highlight-ipynb')
return _pygments_highlight(source, formatter, language)
c = Config({'CSSHtmlHeaderTransformer':
{'enabled':True, 'highlight_class':'highlight-ipynb'}})
exportHtml = HTMLExporter( config=c, filters={'highlight': my_highlight} )
body, resources = exportHtml.from_notebook_node(double11_notebook)
In [12]:
from jinja2 import DictLoader
dl = DictLoader({'full.tpl':
"""
{%- extends 'basic.tpl' -%}
{% block footer %}
FOOOOOOOOTEEEEER
{% endblock footer %}
"""})
exportHtml = HTMLExporter(config=None , filters={'highlight': my_highlight}, extra_loaders=[dl])
body, resources = exportHtml.from_notebook_node(double11_notebook)
In [13]:
HTML(body)
Out[13]: