Show More
1 | NO CONTENT: new file 100755 |
|
NO CONTENT: new file 100755 |
1 | NO CONTENT: new file 100755 |
|
NO CONTENT: new file 100755 |
1 | NO CONTENT: new file 100755 |
|
NO CONTENT: new file 100755 |
1 | NO CONTENT: new file 100755 |
|
NO CONTENT: new file 100755 |
@@ -0,0 +1,1 b'' | |||||
|
1 | from api.convert import * No newline at end of file |
@@ -32,22 +32,23 b' def export(nb, config=None, transformers=None, filters=None, exporter_type=Expor' | |||||
32 | #Check arguments |
|
32 | #Check arguments | |
33 | if exporter_type is None: |
|
33 | if exporter_type is None: | |
34 | raise TypeError("Exporter is None") |
|
34 | raise TypeError("Exporter is None") | |
35 |
elif not is |
|
35 | elif not issubclass(exporter_type, Exporter): | |
36 | raise TypeError("Exporter type does not inherit from Exporter (base)") |
|
36 | raise TypeError("Exporter type does not inherit from Exporter (base)") | |
37 |
|
37 | |||
38 | if nb is None: |
|
38 | if nb is None: | |
39 | raise TypeError("nb is None") |
|
39 | raise TypeError("nb is None") | |
40 |
|
40 | |||
41 | #Create the exporter |
|
41 | #Create the exporter | |
42 | exporter_instance = exporter_type(transformers, filters, config) |
|
42 | exporter_instance = exporter_type(preprocessors=transformers, jinja_filters=filters, config=config) | |
43 |
|
43 | |||
44 | #Try to convert the notebook using the appropriate conversion function. |
|
44 | #Try to convert the notebook using the appropriate conversion function. | |
45 | if isinstance(nb, NotebookNode): |
|
45 | if isinstance(nb, NotebookNode): | |
46 |
|
|
46 | output, resources = exporter_instance.from_notebook_node(nb) | |
47 | elif isinstance(nb, str): |
|
47 | elif isinstance(nb, basestring): | |
48 |
|
|
48 | output, resources = exporter_instance.from_filename(nb) | |
49 | else: |
|
49 | else: | |
50 |
|
|
50 | output, resources = exporter_instance.from_file(nb) | |
|
51 | return output, resources, exporter_instance | |||
51 |
|
52 | |||
52 |
|
53 | |||
53 | def export_sphinx(nb, config=None, transformers=None, filters=None): |
|
54 | def export_sphinx(nb, config=None, transformers=None, filters=None): |
@@ -35,15 +35,15 b' from jinja2 import Environment, FileSystemLoader' | |||||
35 | from markdown import markdown |
|
35 | from markdown import markdown | |
36 |
|
36 | |||
37 | # local import |
|
37 | # local import | |
38 | import filters.strings |
|
38 | import nbconvert.filters.strings | |
39 | import filters.markdown |
|
39 | import nbconvert.filters.markdown | |
40 | import filters.latex |
|
40 | import nbconvert.filters.latex | |
41 | import filters.datatypefilter |
|
41 | import nbconvert.filters.datatypefilter | |
42 | import filters.pygments |
|
42 | import nbconvert.filters.pygments | |
43 | import filters.ansi |
|
43 | import nbconvert.filters.ansi | |
44 |
|
44 | |||
45 | import transformers.extractfigure |
|
45 | import nbconvert.transformers.extractfigure | |
46 | import transformers.coalescestreams |
|
46 | import nbconvert.transformers.coalescestreams | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | #----------------------------------------------------------------------------- |
|
49 | #----------------------------------------------------------------------------- | |
@@ -125,7 +125,7 b' class Exporter(Configurable):' | |||||
125 | #Load user filters. Overwrite existing filters if need be. |
|
125 | #Load user filters. Overwrite existing filters if need be. | |
126 | if not jinja_filters is None: |
|
126 | if not jinja_filters is None: | |
127 | for key, user_filter in jinja_filters.iteritems(): |
|
127 | for key, user_filter in jinja_filters.iteritems(): | |
128 |
if is |
|
128 | if issubclass(user_filter, MetaHasTraits): | |
129 | self.environment.filters[key] = user_filter(config=config) |
|
129 | self.environment.filters[key] = user_filter(config=config) | |
130 | else: |
|
130 | else: | |
131 | self.environment.filters[key] = user_filter |
|
131 | self.environment.filters[key] = user_filter | |
@@ -151,7 +151,7 b' class Exporter(Configurable):' | |||||
151 |
|
151 | |||
152 |
|
152 | |||
153 | def register_transformer(self, transformer): |
|
153 | def register_transformer(self, transformer): | |
154 | if MetaHasTraits(transformer): |
|
154 | if isinstance(transformer, MetaHasTraits): | |
155 | transformer_instance = transformer(config=self.config) |
|
155 | transformer_instance = transformer(config=self.config) | |
156 | self.preprocessors.append(transformer_instance) |
|
156 | self.preprocessors.append(transformer_instance) | |
157 | return transformer_instance |
|
157 | return transformer_instance | |
@@ -161,7 +161,7 b' class Exporter(Configurable):' | |||||
161 |
|
161 | |||
162 |
|
162 | |||
163 | def register_filter(self, name, filter): |
|
163 | def register_filter(self, name, filter): | |
164 |
if |
|
164 | if isinstance(filter, MetaHasTraits): | |
165 | self.environment.filters[name] = filter(config=self.config) |
|
165 | self.environment.filters[name] = filter(config=self.config) | |
166 | else: |
|
166 | else: | |
167 | self.environment.filters[name] = filter |
|
167 | self.environment.filters[name] = filter | |
@@ -171,30 +171,30 b' class Exporter(Configurable):' | |||||
171 | # Protected and Private methods ######################################### |
|
171 | # Protected and Private methods ######################################### | |
172 |
|
172 | |||
173 | def _register_transformers(self): |
|
173 | def _register_transformers(self): | |
174 | self.register_transformer(transformers.coalescestreams.coalesce_streams) |
|
174 | self.register_transformer(nbconvert.transformers.coalescestreams.coalesce_streams) | |
175 |
|
175 | |||
176 | #Remember the figure extraction transformer so it can be enabled and |
|
176 | #Remember the figure extraction transformer so it can be enabled and | |
177 | #disabled easily later. |
|
177 | #disabled easily later. | |
178 | self.extract_figure_transformer = self.register_transformer(transformers.extractfigure.ExtractFigureTransformer) |
|
178 | self.extract_figure_transformer = self.register_transformer(nbconvert.transformers.extractfigure.ExtractFigureTransformer) | |
179 |
|
179 | |||
180 |
|
180 | |||
181 | def _register_filters(self): |
|
181 | def _register_filters(self): | |
182 | self.register_filter('indent', indent) |
|
182 | self.register_filter('indent', indent) | |
183 | self.register_filter('markdown', markdown) |
|
183 | self.register_filter('markdown', markdown) | |
184 | self.register_filter('ansi2html', filters.ansi.ansi2html) |
|
184 | self.register_filter('ansi2html', nbconvert.filters.ansi.ansi2html) | |
185 | self.register_filter('filter_data_type', filters.datatypefilter.DataTypeFilter) |
|
185 | self.register_filter('filter_data_type', nbconvert.filters.datatypefilter.DataTypeFilter) | |
186 | self.register_filter('get_lines', filters.strings.get_lines) |
|
186 | self.register_filter('get_lines', nbconvert.filters.strings.get_lines) | |
187 | self.register_filter('highlight', filters.pygments.highlight) |
|
187 | self.register_filter('highlight', nbconvert.filters.pygments.highlight) | |
188 | self.register_filter('highlight2html', filters.pygments.highlight) |
|
188 | self.register_filter('highlight2html', nbconvert.filters.pygments.highlight) | |
189 | self.register_filter('highlight2latex', filters.pygments.highlight2latex) |
|
189 | self.register_filter('highlight2latex', nbconvert.filters.pygments.highlight2latex) | |
190 | self.register_filter('markdown2latex', filters.markdown.markdown2latex) |
|
190 | self.register_filter('markdown2latex', nbconvert.filters.markdown.markdown2latex) | |
191 | self.register_filter('markdown2rst', filters.markdown.markdown2rst) |
|
191 | self.register_filter('markdown2rst', nbconvert.filters.markdown.markdown2rst) | |
192 | self.register_filter('pycomment', filters.strings.python_comment) |
|
192 | self.register_filter('pycomment', nbconvert.filters.strings.python_comment) | |
193 | self.register_filter('rm_ansi', filters.ansi.remove_ansi) |
|
193 | self.register_filter('rm_ansi', nbconvert.filters.ansi.remove_ansi) | |
194 | self.register_filter('rm_dollars', filters.strings.strip_dollars) |
|
194 | self.register_filter('rm_dollars', nbconvert.filters.strings.strip_dollars) | |
195 | self.register_filter('rm_fake', filters.strings.rm_fake) |
|
195 | self.register_filter('rm_fake', nbconvert.filters.strings.rm_fake) | |
196 | self.register_filter('rm_math_space', filters.latex.rm_math_space) |
|
196 | self.register_filter('rm_math_space', nbconvert.filters.latex.rm_math_space) | |
197 | self.register_filter('wrap', filters.strings.wrap) |
|
197 | self.register_filter('wrap', nbconvert.filters.strings.wrap) | |
198 |
|
198 | |||
199 |
|
199 | |||
200 | def _init_environment(self): |
|
200 | def _init_environment(self): |
@@ -15,7 +15,7 b'' | |||||
15 |
|
15 | |||
16 | # local import |
|
16 | # local import | |
17 | import exporter |
|
17 | import exporter | |
18 | import transformers.csshtmlheader |
|
18 | import nbconvert.transformers.csshtmlheader | |
19 | from IPython.utils.traitlets import Unicode |
|
19 | from IPython.utils.traitlets import Unicode | |
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
@@ -38,5 +38,5 b' class HtmlExporter(exporter.Exporter):' | |||||
38 | super(exporter.Exporter, self)._register_transformers() |
|
38 | super(exporter.Exporter, self)._register_transformers() | |
39 |
|
39 | |||
40 | #Register latex transformer |
|
40 | #Register latex transformer | |
41 | self.register_transformer(transformers.csshtmlheader.CSSHtmlHeaderTransformer) |
|
41 | self.register_transformer(nbconvert.transformers.csshtmlheader.CSSHtmlHeaderTransformer) | |
42 | No newline at end of file |
|
42 |
@@ -21,9 +21,9 b' from jinja2 import Environment, FileSystemLoader' | |||||
21 |
|
21 | |||
22 | # local import |
|
22 | # local import | |
23 | import exporter |
|
23 | import exporter | |
24 | import filters.latex |
|
24 | import nbconvert.filters.latex | |
25 | import filters.pygments |
|
25 | import nbconvert.filters.pygments | |
26 | from transformers.latex import LatexTransformer |
|
26 | from nbconvert.transformers.latex import LatexTransformer | |
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 | # Globals and constants |
|
28 | # Globals and constants | |
29 | #----------------------------------------------------------------------------- |
|
29 | #----------------------------------------------------------------------------- |
@@ -14,14 +14,14 b'' | |||||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | # local import |
|
16 | # local import | |
17 |
import html |
|
17 | import html | |
18 | import transformers.revealhelp |
|
18 | import nbconvert.transformers.revealhelp | |
19 | from IPython.utils.traitlets import Unicode |
|
19 | from IPython.utils.traitlets import Unicode | |
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Classes |
|
22 | # Classes | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 |
class RevealExporter(html |
|
24 | class RevealExporter(html.HtmlExporter): | |
25 |
|
25 | |||
26 | file_extension = Unicode( |
|
26 | file_extension = Unicode( | |
27 | 'reveal.html', config=True, |
|
27 | 'reveal.html', config=True, |
@@ -29,21 +29,4 b' class RstExporter(exporter.Exporter):' | |||||
29 | template_file = Unicode( |
|
29 | template_file = Unicode( | |
30 | 'rst', config=True, |
|
30 | 'rst', config=True, | |
31 | help="Name of the template file to use") |
|
31 | help="Name of the template file to use") | |
32 |
|
32 | No newline at end of file | ||
33 | def _register_filters(self): |
|
|||
34 |
|
||||
35 | #Register the filters of the base class. |
|
|||
36 | super(exporter.Exporter, self)._register_filters() |
|
|||
37 |
|
||||
38 | #Add latex filters to the Jinja2 environment |
|
|||
39 | #self.register_filter('escape_tex', filters.latex.escape_tex) |
|
|||
40 |
|
||||
41 |
|
||||
42 | def _register_transformers(self): |
|
|||
43 |
|
||||
44 | #Register the transformers of the base class. |
|
|||
45 | super(exporter.Exporter, self)._register_transformers() |
|
|||
46 |
|
||||
47 | #Register latex transformer |
|
|||
48 | #self.register_transformer(LatexTransformer) |
|
|||
49 |
|
@@ -14,7 +14,7 b'' | |||||
14 | # local import |
|
14 | # local import | |
15 | import latex |
|
15 | import latex | |
16 | from IPython.utils.traitlets import Unicode |
|
16 | from IPython.utils.traitlets import Unicode | |
17 | from transformers.sphinx import SphinxTransformer |
|
17 | from nbconvert.transformers.sphinx import SphinxTransformer | |
18 | #----------------------------------------------------------------------------- |
|
18 | #----------------------------------------------------------------------------- | |
19 | # Classes |
|
19 | # Classes | |
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- |
@@ -1,5 +1,5 b'' | |||||
1 | # Our own imports |
|
1 | # Our own imports | |
2 | from utils.lexers import IPythonLexer |
|
2 | from nbconvert.utils.lexers import IPythonLexer | |
3 |
|
3 | |||
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | # Globals and constants |
|
5 | # Globals and constants |
@@ -19,7 +19,7 b' from __future__ import print_function, absolute_import' | |||||
19 | # Our own imports |
|
19 | # Our own imports | |
20 | # Needed to override transformer |
|
20 | # Needed to override transformer | |
21 | from .activatable import (ActivatableTransformer) |
|
21 | from .activatable import (ActivatableTransformer) | |
22 | from filters import latex |
|
22 | from nbconvert.filters import latex | |
23 |
|
23 | |||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | # Classes |
|
25 | # Classes |
General Comments 0
You need to be logged in to leave comments.
Login now