##// END OF EJS Templates
make default language highlight configurable for html
Matthias BUSSONNIER -
Show More
@@ -43,7 +43,7 b' default_filters = {'
43 43 'ansi2html': filters.ansi2html,
44 44 'filter_data_type': filters.DataTypeFilter,
45 45 'get_lines': filters.get_lines,
46 'highlight2html': filters.highlight2html,
46 'highlight2html': filters.Highlight2Html,
47 47 'highlight2latex': filters.highlight2latex,
48 48 'ipython2python': filters.ipython2python,
49 49 'posix_path': filters.posix_path,
@@ -18,6 +18,8 b' from pygments import highlight as pygements_highlight'
18 18 from pygments.lexers import get_lexer_by_name
19 19 from pygments.formatters import HtmlFormatter
20 20 from pygments.formatters import LatexFormatter
21 from IPython.config import catch_config_error, Configurable
22 from IPython.utils.traitlets import Unicode
21 23
22 24 # Our own imports
23 25 from IPython.nbconvert.utils.lexers import IPythonLexer
@@ -33,26 +35,32 b" MULTILINE_OUTPUTS = ['text', 'html', 'svg', 'latex', 'javascript', 'json']"
33 35 #-----------------------------------------------------------------------------
34 36
35 37 __all__ = [
36 'highlight2html',
38 'Highlight2Html',
37 39 'highlight2latex'
38 40 ]
39 41
40 42
41 def highlight2html(source, language='ipython', metadata=None):
42 """
43 Return a syntax-highlighted version of the input source as html output.
43 class Highlight2Html(Configurable):
44 44
45 Parameters
46 ----------
47 source : str
48 source of the cell to highlight
49 language : str
50 language to highlight the syntax of
51 metadata : NotebookNode cell metadata
52 metadata of the cell to highlight
53 """
45 language = Unicode('ipython', config=True, help='default highlight language')
46
47 def __call__(self, source, language=None, metadata=None):
48 """
49 Return a syntax-highlighted version of the input source as html output.
50
51 Parameters
52 ----------
53 source : str
54 source of the cell to highlight
55 language : str
56 language to highlight the syntax of
57 metadata : NotebookNode cell metadata
58 metadata of the cell to highlight
59 """
60 if not language:
61 language=self.language
54 62
55 return _pygment_highlight(source, HtmlFormatter(), language, metadata)
63 return _pygment_highlight(source, HtmlFormatter(), language, metadata)
56 64
57 65
58 66 def highlight2latex(source, language='ipython', metadata=None, strip_verbatim=False):
General Comments 0
You need to be logged in to leave comments. Login now