Show More
@@ -149,7 +149,7 b' def main():' | |||||
149 |
|
149 | |||
150 | app = NbconvertApp.instance() |
|
150 | app = NbconvertApp.instance() | |
151 | app.description = __doc__ |
|
151 | app.description = __doc__ | |
152 |
app. |
|
152 | app.start(argv=sys.argv) | |
153 |
|
153 | |||
154 | if __name__ == '__main__': |
|
154 | if __name__ == '__main__': | |
155 | main() No newline at end of file |
|
155 | main() |
@@ -39,7 +39,7 b' import nbconvert.filters.strings' | |||||
39 | import nbconvert.filters.markdown |
|
39 | import nbconvert.filters.markdown | |
40 | import nbconvert.filters.latex |
|
40 | import nbconvert.filters.latex | |
41 | import nbconvert.filters.datatypefilter |
|
41 | import nbconvert.filters.datatypefilter | |
42 |
import nbconvert.filters. |
|
42 | import nbconvert.filters.highlight | |
43 | import nbconvert.filters.ansi |
|
43 | import nbconvert.filters.ansi | |
44 |
|
44 | |||
45 | import nbconvert.transformers.extractfigure |
|
45 | import nbconvert.transformers.extractfigure | |
@@ -184,9 +184,9 b' class Exporter(Configurable):' | |||||
184 | self.register_filter('ansi2html', nbconvert.filters.ansi.ansi2html) |
|
184 | self.register_filter('ansi2html', nbconvert.filters.ansi.ansi2html) | |
185 | self.register_filter('filter_data_type', nbconvert.filters.datatypefilter.DataTypeFilter) |
|
185 | self.register_filter('filter_data_type', nbconvert.filters.datatypefilter.DataTypeFilter) | |
186 | self.register_filter('get_lines', nbconvert.filters.strings.get_lines) |
|
186 | self.register_filter('get_lines', nbconvert.filters.strings.get_lines) | |
187 |
self.register_filter('highlight', nbconvert.filters. |
|
187 | self.register_filter('highlight', nbconvert.filters.highlight.highlight) | |
188 |
self.register_filter('highlight2html', nbconvert.filters. |
|
188 | self.register_filter('highlight2html', nbconvert.filters.highlight.highlight) | |
189 |
self.register_filter('highlight2latex', nbconvert.filters. |
|
189 | self.register_filter('highlight2latex', nbconvert.filters.highlight.highlight2latex) | |
190 | self.register_filter('markdown2latex', nbconvert.filters.markdown.markdown2latex) |
|
190 | self.register_filter('markdown2latex', nbconvert.filters.markdown.markdown2latex) | |
191 | self.register_filter('markdown2rst', nbconvert.filters.markdown.markdown2rst) |
|
191 | self.register_filter('markdown2rst', nbconvert.filters.markdown.markdown2rst) | |
192 | self.register_filter('pycomment', nbconvert.filters.strings.python_comment) |
|
192 | self.register_filter('pycomment', nbconvert.filters.strings.python_comment) |
@@ -35,7 +35,7 b' class HtmlExporter(exporter.Exporter):' | |||||
35 | def _register_transformers(self): |
|
35 | def _register_transformers(self): | |
36 |
|
36 | |||
37 | #Register the transformers of the base class. |
|
37 | #Register the transformers of the base class. | |
38 |
super( |
|
38 | super(HtmlExporter, self)._register_transformers() | |
39 |
|
39 | |||
40 | #Register latex transformer |
|
40 | #Register latex transformer | |
41 | self.register_transformer(nbconvert.transformers.csshtmlheader.CSSHtmlHeaderTransformer) |
|
41 | self.register_transformer(nbconvert.transformers.csshtmlheader.CSSHtmlHeaderTransformer) |
@@ -22,15 +22,15 b' from jinja2 import Environment, FileSystemLoader' | |||||
22 | # local import |
|
22 | # local import | |
23 | import exporter |
|
23 | import exporter | |
24 | import nbconvert.filters.latex |
|
24 | import nbconvert.filters.latex | |
25 |
import nbconvert.filters. |
|
25 | import nbconvert.filters.highlight | |
26 | from nbconvert.transformers.latex import LatexTransformer |
|
26 | from nbconvert.transformers.latex import LatexTransformer | |
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 | # Globals and constants |
|
28 | # Globals and constants | |
29 | #----------------------------------------------------------------------------- |
|
29 | #----------------------------------------------------------------------------- | |
30 |
|
30 | |||
31 | #Latex Jinja2 constants |
|
31 | #Latex Jinja2 constants | |
32 | LATEX_TEMPLATE_PATH = "/../templates/tex/" |
|
32 | LATEX_TEMPLATE_PATH = "/../templates/latex/" | |
33 | LATEX_TEMPLATE_SKELETON_PATH = "/../templates/tex/skeleton/" |
|
33 | LATEX_TEMPLATE_SKELETON_PATH = "/../templates/latex/skeleton/" | |
34 |
|
34 | |||
35 | #Special Jinja2 syntax that will not conflict when exporting latex. |
|
35 | #Special Jinja2 syntax that will not conflict when exporting latex. | |
36 | LATEX_JINJA_COMMENT_BLOCK = ["((=", "=))"] |
|
36 | LATEX_JINJA_COMMENT_BLOCK = ["((=", "=))"] | |
@@ -50,13 +50,13 b' class LatexExporter(exporter.Exporter):' | |||||
50 | help="Extension of the file that should be written to disk") |
|
50 | help="Extension of the file that should be written to disk") | |
51 |
|
51 | |||
52 | template_file = Unicode( |
|
52 | template_file = Unicode( | |
53 |
' |
|
53 | 'base', config=True, | |
54 | help="Name of the template file to use") |
|
54 | help="Name of the template file to use") | |
55 |
|
55 | |||
56 | def __init__(self, preprocessors=None, jinja_filters=None, config=None, **kw): |
|
56 | def __init__(self, preprocessors=None, jinja_filters=None, config=None, **kw): | |
57 |
|
57 | |||
58 | #Call base class constructor. |
|
58 | #Call base class constructor. | |
59 |
super( |
|
59 | super(LatexExporter, self).__init__(preprocessors, jinja_filters, config, **kw) | |
60 |
|
60 | |||
61 | self.extract_figure_transformer.display_data_priority = ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text'] |
|
61 | self.extract_figure_transformer.display_data_priority = ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text'] | |
62 | self.extract_figure_transformer.extra_ext_map={'svg':'pdf'} |
|
62 | self.extract_figure_transformer.extra_ext_map={'svg':'pdf'} | |
@@ -83,16 +83,16 b' class LatexExporter(exporter.Exporter):' | |||||
83 | def _register_filters(self): |
|
83 | def _register_filters(self): | |
84 |
|
84 | |||
85 | #Register the filters of the base class. |
|
85 | #Register the filters of the base class. | |
86 |
super( |
|
86 | super(LatexExporter, self)._register_filters() | |
87 |
|
87 | |||
88 | #Add latex filters to the Jinja2 environment |
|
88 | #Add latex filters to the Jinja2 environment | |
89 | self.register_filter('escape_tex', filters.latex.escape_tex) |
|
89 | self.register_filter('escape_tex', nbconvert.filters.latex.escape_tex) | |
90 |
self.register_filter('highlight', filters. |
|
90 | self.register_filter('highlight', nbconvert.filters.highlight.highlight2latex) | |
91 |
|
91 | |||
92 | def _register_transformers(self): |
|
92 | def _register_transformers(self): | |
93 |
|
93 | |||
94 | #Register the transformers of the base class. |
|
94 | #Register the transformers of the base class. | |
95 |
super( |
|
95 | super(LatexExporter, self)._register_transformers() | |
96 |
|
96 | |||
97 | #Register latex transformer |
|
97 | #Register latex transformer | |
98 | self.register_transformer(LatexTransformer) |
|
98 | self.register_transformer(LatexTransformer) |
@@ -33,7 +33,7 b' class PythonExporter(exporter.Exporter):' | |||||
33 | def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): |
|
33 | def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): | |
34 |
|
34 | |||
35 | #Call base class constructor. |
|
35 | #Call base class constructor. | |
36 |
super( |
|
36 | super(PythonExporter, self).__init__(preprocessors, jinja_filters, config, **kw) | |
37 |
|
37 | |||
38 | #Set defaults |
|
38 | #Set defaults | |
39 | self.extract_figure_transformer.enabled = False |
|
39 | self.extract_figure_transformer.enabled = False |
@@ -34,8 +34,8 b' class RevealExporter(html.HtmlExporter):' | |||||
34 | def _register_transformers(self): |
|
34 | def _register_transformers(self): | |
35 |
|
35 | |||
36 | #Register the transformers of the base class. |
|
36 | #Register the transformers of the base class. | |
37 |
super( |
|
37 | super(RevealExporter, self)._register_transformers() | |
38 |
|
38 | |||
39 | #Register reveal help transformer |
|
39 | #Register reveal help transformer | |
40 | self.register_transformer(transformers.revealhelp.RevealHelpTransformer) |
|
40 | self.register_transformer(nbconvert.transformers.revealhelp.RevealHelpTransformer) | |
41 | No newline at end of file |
|
41 |
@@ -21,13 +21,13 b' from nbconvert.transformers.sphinx import SphinxTransformer' | |||||
21 | class SphinxExporter(latex.LatexExporter): |
|
21 | class SphinxExporter(latex.LatexExporter): | |
22 |
|
22 | |||
23 | template_file = Unicode( |
|
23 | template_file = Unicode( | |
24 | 'sphinxhowto', config=True, |
|
24 | 'sphinx_howto', config=True, | |
25 | help="Name of the template file to use") |
|
25 | help="Name of the template file to use") | |
26 |
|
26 | |||
27 | def _register_transformers(self): |
|
27 | def _register_transformers(self): | |
28 |
|
28 | |||
29 | #Register the transformers of the base class. |
|
29 | #Register the transformers of the base class. | |
30 |
super( |
|
30 | super(SphinxExporter, self)._register_transformers() | |
31 |
|
31 | |||
32 | #Register sphinx latex transformer |
|
32 | #Register sphinx latex transformer | |
33 | self.register_transformer(SphinxTransformer) |
|
33 | self.register_transformer(SphinxTransformer) |
@@ -22,10 +22,9 b' class DataTypeFilter(object):' | |||||
22 | display_data_priority = None |
|
22 | display_data_priority = None | |
23 |
|
23 | |||
24 | def __init__(self, display_data_priority): |
|
24 | def __init__(self, display_data_priority): | |
25 | super(object, self).__init__() |
|
|||
26 |
|
25 | |||
27 | #Make sure that the display data priority variably is not None. |
|
26 | #Make sure that the display data priority variably is not None. | |
28 |
if |
|
27 | if display_data_priority is None: | |
29 | raise TypeError |
|
28 | raise TypeError | |
30 | else: |
|
29 | else: | |
31 | self.display_data_priority = display_data_priority |
|
30 | self.display_data_priority = display_data_priority |
@@ -1,3 +1,9 b'' | |||||
|
1 | ||||
|
2 | from pygments import highlight as pygements_highlight | |||
|
3 | from pygments.lexers import get_lexer_by_name | |||
|
4 | from pygments.formatters import HtmlFormatter | |||
|
5 | from pygments.formatters import LatexFormatter | |||
|
6 | ||||
1 | # Our own imports |
|
7 | # Our own imports | |
2 | from nbconvert.utils.lexers import IPythonLexer |
|
8 | from nbconvert.utils.lexers import IPythonLexer | |
3 |
|
9 | |||
@@ -14,26 +20,22 b" def highlight(src, lang='ipython'):" | |||||
14 | """ |
|
20 | """ | |
15 | Return a syntax-highlighted version of the input source as html output. |
|
21 | Return a syntax-highlighted version of the input source as html output. | |
16 | """ |
|
22 | """ | |
17 | from pygments.formatters import HtmlFormatter |
|
23 | ||
18 | return pygment_highlight(src, HtmlFormatter(), lang) |
|
24 | return _pygment_highlight(src, HtmlFormatter(), lang) | |
19 |
|
25 | |||
20 | def highlight2latex(src, lang='ipython'): |
|
26 | def highlight2latex(src, lang='ipython'): | |
21 | """ |
|
27 | """ | |
22 | Return a syntax-highlighted version of the input source as latex output. |
|
28 | Return a syntax-highlighted version of the input source as latex output. | |
23 | """ |
|
29 | """ | |
24 | from pygments.formatters import LatexFormatter |
|
30 | return _pygment_highlight(src, LatexFormatter(), lang) | |
25 | return pygment_highlight(src, LatexFormatter(), lang) |
|
|||
26 |
|
31 | |||
27 | def pygment_highlight(src, output_formatter, lang='ipython'): |
|
32 | def _pygment_highlight(src, output_formatter, lang='ipython'): | |
28 | """ |
|
33 | """ | |
29 | Return a syntax-highlighted version of the input source |
|
34 | Return a syntax-highlighted version of the input source | |
30 | """ |
|
35 | """ | |
31 | from pygments import highlight |
|
|||
32 | from pygments.lexers import get_lexer_by_name |
|
|||
33 |
|
||||
34 | if lang == 'ipython': |
|
36 | if lang == 'ipython': | |
35 | lexer = IPythonLexer() |
|
37 | lexer = IPythonLexer() | |
36 | else: |
|
38 | else: | |
37 | lexer = get_lexer_by_name(lang, stripall=True) |
|
39 | lexer = get_lexer_by_name(lang, stripall=True) | |
38 |
|
40 | |||
39 | return highlight(src, lexer, output_formatter) |
|
41 | return pygements_highlight(src, lexer, output_formatter) |
@@ -28,7 +28,7 b' consider calling super even if it is a leave block, we might insert more blocks ' | |||||
28 | ((*- for worksheet in nb.worksheets -*)) |
|
28 | ((*- for worksheet in nb.worksheets -*)) | |
29 | ((*- for cell in worksheet.cells -*)) |
|
29 | ((*- for cell in worksheet.cells -*)) | |
30 | ((*- block any_cell scoped -*)) |
|
30 | ((*- block any_cell scoped -*)) | |
31 | ((*- if cell.type in ['code'] -*)) |
|
31 | ((*- if cell.cell_type in ['code'] -*)) | |
32 | ((*- block codecell scoped -*)) |
|
32 | ((*- block codecell scoped -*)) | |
33 | ((*- block input_group -*)) |
|
33 | ((*- block input_group -*)) | |
34 | ((*- block in_prompt -*))((*- endblock in_prompt -*)) |
|
34 | ((*- block in_prompt -*))((*- endblock in_prompt -*)) | |
@@ -70,13 +70,13 b' consider calling super even if it is a leave block, we might insert more blocks ' | |||||
70 | ((*- endblock output_group -*)) |
|
70 | ((*- endblock output_group -*)) | |
71 | ((*- endif -*)) |
|
71 | ((*- endif -*)) | |
72 | ((*- endblock codecell -*)) |
|
72 | ((*- endblock codecell -*)) | |
73 | ((*- elif cell.type in ['markdown'] -*)) |
|
73 | ((*- elif cell.cell_type in ['markdown'] -*)) | |
74 | ((*- block markdowncell scoped-*)) |
|
74 | ((*- block markdowncell scoped-*)) | |
75 | ((*- endblock markdowncell -*)) |
|
75 | ((*- endblock markdowncell -*)) | |
76 | ((*- elif cell.type in ['heading'] -*)) |
|
76 | ((*- elif cell.cell_type in ['heading'] -*)) | |
77 | ((*- block headingcell scoped-*)) |
|
77 | ((*- block headingcell scoped-*)) | |
78 | ((*- endblock headingcell -*)) |
|
78 | ((*- endblock headingcell -*)) | |
79 | ((*- elif cell.type in ['raw'] -*)) |
|
79 | ((*- elif cell.cell_type in ['raw'] -*)) | |
80 | ((*- block rawcell scoped-*)) |
|
80 | ((*- block rawcell scoped-*)) | |
81 | ((*- endblock rawcell -*)) |
|
81 | ((*- endblock rawcell -*)) | |
82 | ((*- else -*)) |
|
82 | ((*- else -*)) |
@@ -3,7 +3,7 b'' | |||||
3 | Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the |
|
3 | Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the | |
4 | template is derived directly from Sphinx source. |
|
4 | template is derived directly from Sphinx source. | |
5 |
|
5 | |||
6 |
Inheritance: null>display_priority |
|
6 | Inheritance: null>display_priority | |
7 |
|
7 | |||
8 | Note: For best display, use latex syntax highlighting. =)) |
|
8 | Note: For best display, use latex syntax highlighting. =)) | |
9 |
|
9 |
@@ -8,7 +8,7 b'' | |||||
8 |
|
8 | |||
9 | ==========================================================================)) |
|
9 | ==========================================================================)) | |
10 |
|
10 | |||
11 |
((*- extends ' |
|
11 | ((*- extends 'sphinx_base.tplx' -*)) | |
12 |
|
12 | |||
13 | ((* set parentdocumentclass = 'article' *)) |
|
13 | ((* set parentdocumentclass = 'article' *)) | |
14 | ((* set documentclass = 'howto' *)) |
|
14 | ((* set documentclass = 'howto' *)) |
@@ -8,7 +8,7 b'' | |||||
8 |
|
8 | |||
9 | ==========================================================================)) |
|
9 | ==========================================================================)) | |
10 |
|
10 | |||
11 |
((*- extends ' |
|
11 | ((*- extends 'sphinx_base.tplx' -*)) | |
12 |
|
12 | |||
13 | ((* set parentdocumentclass = 'report' *)) |
|
13 | ((* set parentdocumentclass = 'report' *)) | |
14 | ((* set documentclass = 'manual' *)) |
|
14 | ((* set documentclass = 'manual' *)) |
@@ -27,7 +27,7 b' consider calling super even if it is a leave block, we might insert more blocks ' | |||||
27 | {%- for worksheet in nb.worksheets -%} |
|
27 | {%- for worksheet in nb.worksheets -%} | |
28 | {%- for cell in worksheet.cells -%} |
|
28 | {%- for cell in worksheet.cells -%} | |
29 | {%- block any_cell scoped -%} |
|
29 | {%- block any_cell scoped -%} | |
30 | {%- if cell.type in ['code'] -%} |
|
30 | {%- if cell.cell_type in ['code'] -%} | |
31 | {%- block codecell scoped -%} |
|
31 | {%- block codecell scoped -%} | |
32 | {%- block input_group -%} |
|
32 | {%- block input_group -%} | |
33 | {%- block in_prompt -%}{%- endblock in_prompt -%} |
|
33 | {%- block in_prompt -%}{%- endblock in_prompt -%} | |
@@ -69,13 +69,13 b' consider calling super even if it is a leave block, we might insert more blocks ' | |||||
69 | {%- endblock output_group -%} |
|
69 | {%- endblock output_group -%} | |
70 | {%- endif -%} |
|
70 | {%- endif -%} | |
71 | {%- endblock codecell -%} |
|
71 | {%- endblock codecell -%} | |
72 | {%- elif cell.type in ['markdown'] -%} |
|
72 | {%- elif cell.cell_type in ['markdown'] -%} | |
73 | {%- block markdowncell scoped-%} |
|
73 | {%- block markdowncell scoped-%} | |
74 | {%- endblock markdowncell -%} |
|
74 | {%- endblock markdowncell -%} | |
75 | {%- elif cell.type in ['heading'] -%} |
|
75 | {%- elif cell.cell_type in ['heading'] -%} | |
76 | {%- block headingcell scoped-%} |
|
76 | {%- block headingcell scoped-%} | |
77 | {%- endblock headingcell -%} |
|
77 | {%- endblock headingcell -%} | |
78 | {%- elif cell.type in ['raw'] -%} |
|
78 | {%- elif cell.cell_type in ['raw'] -%} | |
79 | {%- block rawcell scoped-%} |
|
79 | {%- block rawcell scoped-%} | |
80 | {%- endblock rawcell -%} |
|
80 | {%- endblock rawcell -%} | |
81 | {%- else -%} |
|
81 | {%- else -%} |
@@ -10,7 +10,7 b' class ActivatableTransformer(ConfigurableTransformer):' | |||||
10 | c.YourTransformerName.enabled = True |
|
10 | c.YourTransformerName.enabled = True | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 |
enabled = Bool( |
|
13 | enabled = Bool(True, config=True) | |
14 |
|
14 | |||
15 | def __call__(self, nb, other): |
|
15 | def __call__(self, nb, other): | |
16 | if not self.enabled : |
|
16 | if not self.enabled : |
General Comments 0
You need to be logged in to leave comments.
Login now