From 02f025c2be7c007e3e2770a54aecb91e62f28a34 2013-10-18 19:44:09
From: Matthias BUSSONNIER <bussonniermatthias@gmail.com>
Date: 2013-10-18 19:44:09
Subject: [PATCH] make default language highlight configurable for html

---

diff --git a/IPython/nbconvert/exporters/templateexporter.py b/IPython/nbconvert/exporters/templateexporter.py
index f9cc397..782410b 100644
--- a/IPython/nbconvert/exporters/templateexporter.py
+++ b/IPython/nbconvert/exporters/templateexporter.py
@@ -43,7 +43,7 @@ default_filters = {
         'ansi2html': filters.ansi2html,
         'filter_data_type': filters.DataTypeFilter,
         'get_lines': filters.get_lines,
-        'highlight2html': filters.highlight2html,
+        'highlight2html': filters.Highlight2Html,
         'highlight2latex': filters.highlight2latex,
         'ipython2python': filters.ipython2python,
         'posix_path': filters.posix_path,
diff --git a/IPython/nbconvert/filters/highlight.py b/IPython/nbconvert/filters/highlight.py
index b390e6c..0b0374f 100644
--- a/IPython/nbconvert/filters/highlight.py
+++ b/IPython/nbconvert/filters/highlight.py
@@ -18,6 +18,8 @@ from pygments import highlight as pygements_highlight
 from pygments.lexers import get_lexer_by_name
 from pygments.formatters import HtmlFormatter
 from pygments.formatters import LatexFormatter
+from IPython.config import catch_config_error, Configurable
+from IPython.utils.traitlets import Unicode
 
 # Our own imports
 from IPython.nbconvert.utils.lexers import IPythonLexer
@@ -33,26 +35,32 @@ MULTILINE_OUTPUTS = ['text', 'html', 'svg', 'latex', 'javascript', 'json']
 #-----------------------------------------------------------------------------
 
 __all__ = [
-    'highlight2html',
+    'Highlight2Html',
     'highlight2latex'
 ]
 
 
-def highlight2html(source, language='ipython', metadata=None):
-    """
-    Return a syntax-highlighted version of the input source as html output.
+class Highlight2Html(Configurable):
 
-    Parameters
-    ----------
-    source : str
-        source of the cell to highlight
-    language : str
-        language to highlight the syntax of
-    metadata : NotebookNode cell metadata
-        metadata of the cell to highlight
-    """
+    language = Unicode('ipython', config=True, help='default highlight language')
+
+    def __call__(self, source, language=None, metadata=None):
+        """
+        Return a syntax-highlighted version of the input source as html output.
+
+        Parameters
+        ----------
+        source : str
+            source of the cell to highlight
+        language : str
+            language to highlight the syntax of
+        metadata : NotebookNode cell metadata
+            metadata of the cell to highlight
+        """
+        if not language:
+            language=self.language
 
-    return _pygment_highlight(source, HtmlFormatter(), language, metadata)
+        return _pygment_highlight(source, HtmlFormatter(), language, metadata)
 
 
 def highlight2latex(source, language='ipython', metadata=None, strip_verbatim=False):