Show More
@@ -43,7 +43,7 b' default_filters = {' | |||||
43 | 'ansi2html': filters.ansi2html, |
|
43 | 'ansi2html': filters.ansi2html, | |
44 | 'filter_data_type': filters.DataTypeFilter, |
|
44 | 'filter_data_type': filters.DataTypeFilter, | |
45 | 'get_lines': filters.get_lines, |
|
45 | 'get_lines': filters.get_lines, | |
46 |
'highlight2html': filters. |
|
46 | 'highlight2html': filters.Highlight2Html, | |
47 | 'highlight2latex': filters.highlight2latex, |
|
47 | 'highlight2latex': filters.highlight2latex, | |
48 | 'ipython2python': filters.ipython2python, |
|
48 | 'ipython2python': filters.ipython2python, | |
49 | 'posix_path': filters.posix_path, |
|
49 | 'posix_path': filters.posix_path, |
@@ -18,6 +18,8 b' from pygments import highlight as pygements_highlight' | |||||
18 | from pygments.lexers import get_lexer_by_name |
|
18 | from pygments.lexers import get_lexer_by_name | |
19 | from pygments.formatters import HtmlFormatter |
|
19 | from pygments.formatters import HtmlFormatter | |
20 | from pygments.formatters import LatexFormatter |
|
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 | # Our own imports |
|
24 | # Our own imports | |
23 | from IPython.nbconvert.utils.lexers import IPythonLexer |
|
25 | from IPython.nbconvert.utils.lexers import IPythonLexer | |
@@ -33,12 +35,16 b" MULTILINE_OUTPUTS = ['text', 'html', 'svg', 'latex', 'javascript', 'json']" | |||||
33 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
34 |
|
36 | |||
35 | __all__ = [ |
|
37 | __all__ = [ | |
36 |
' |
|
38 | 'Highlight2Html', | |
37 | 'highlight2latex' |
|
39 | 'highlight2latex' | |
38 | ] |
|
40 | ] | |
39 |
|
41 | |||
40 |
|
42 | |||
41 | def highlight2html(source, language='ipython', metadata=None): |
|
43 | class Highlight2Html(Configurable): | |
|
44 | ||||
|
45 | language = Unicode('ipython', config=True, help='default highlight language') | |||
|
46 | ||||
|
47 | def __call__(self, source, language=None, metadata=None): | |||
42 | """ |
|
48 | """ | |
43 | Return a syntax-highlighted version of the input source as html output. |
|
49 | Return a syntax-highlighted version of the input source as html output. | |
44 |
|
50 | |||
@@ -51,6 +57,8 b" def highlight2html(source, language='ipython', metadata=None):" | |||||
51 | metadata : NotebookNode cell metadata |
|
57 | metadata : NotebookNode cell metadata | |
52 | metadata of the cell to highlight |
|
58 | metadata of the cell to highlight | |
53 | """ |
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now