From 8a560994a8e43489101ca4744bb90dab4abd2866 2014-03-05 00:31:31 From: MinRK Date: 2014-03-05 00:31:31 Subject: [PATCH] allow highlighting language to be set from notebook metadata --- diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py index cc77fc7..cc6328d 100644 --- a/IPython/nbconvert/exporters/exporter.py +++ b/IPython/nbconvert/exporters/exporter.py @@ -115,6 +115,9 @@ class Exporter(LoggingConfigurable): """ nb_copy = copy.deepcopy(nb) resources = self._init_resources(resources) + + if 'language' in nb['metadata']: + resources['language'] = nb['metadata']['language'].lower() # Preprocess nb_copy, resources = self._preprocess(nb_copy, resources) diff --git a/IPython/nbconvert/templates/html/basic.tpl b/IPython/nbconvert/templates/html/basic.tpl index 8bc1b1a..aa8c40a 100644 --- a/IPython/nbconvert/templates/html/basic.tpl +++ b/IPython/nbconvert/templates/html/basic.tpl @@ -41,7 +41,7 @@ In [{{ cell.prompt_number }}]: {% block input %}
-{{ cell.input | highlight2html(metadata=cell.metadata) }} +{{ cell.input | highlight2html(language=resources.get('language'), metadata=cell.metadata) }}
{%- endblock input %} diff --git a/IPython/nbconvert/templates/latex/style_python.tplx b/IPython/nbconvert/templates/latex/style_python.tplx index f950af9..43ec107 100644 --- a/IPython/nbconvert/templates/latex/style_python.tplx +++ b/IPython/nbconvert/templates/latex/style_python.tplx @@ -16,6 +16,6 @@ ((* block input scoped *)) \begin{Verbatim}[commandchars=\\\{\}] -((( cell.input | highlight2latex(strip_verbatim=True) | add_prompts ))) +((( cell.input | highlight2latex(language=resources.get('language'), strip_verbatim=True) | add_prompts ))) \end{Verbatim} ((* endblock input *))