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,26 +35,32 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): | |
42 | """ |
|
|||
43 | Return a syntax-highlighted version of the input source as html output. |
|
|||
44 |
|
44 | |||
45 | Parameters |
|
45 | language = Unicode('ipython', config=True, help='default highlight language') | |
46 | ---------- |
|
46 | ||
47 | source : str |
|
47 | def __call__(self, source, language=None, metadata=None): | |
48 | source of the cell to highlight |
|
48 | """ | |
49 | language : str |
|
49 | Return a syntax-highlighted version of the input source as html output. | |
50 | language to highlight the syntax of |
|
50 | ||
51 | metadata : NotebookNode cell metadata |
|
51 | Parameters | |
52 | metadata of the cell to highlight |
|
52 | ---------- | |
53 | """ |
|
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 | def highlight2latex(source, language='ipython', metadata=None, strip_verbatim=False): |
|
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