##// END OF EJS Templates
Docstring decorator
Jonathan Frederic -
Show More
@@ -1,195 +1,195
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """NBConvert is a utility for conversion of IPYNB files.
2 """NBConvert is a utility for conversion of IPYNB files.
3
3
4 Commandline interface for the NBConvert conversion utility. Read the
4 Commandline interface for the NBConvert conversion utility. Read the
5 readme.rst for usage information
5 readme.rst for usage information
6 """
6 """
7 #-----------------------------------------------------------------------------
7 #-----------------------------------------------------------------------------
8 #Copyright (c) 2013, the IPython Development Team.
8 #Copyright (c) 2013, the IPython Development Team.
9 #
9 #
10 #Distributed under the terms of the Modified BSD License.
10 #Distributed under the terms of the Modified BSD License.
11 #
11 #
12 #The full license is in the file COPYING.txt, distributed with this software.
12 #The full license is in the file COPYING.txt, distributed with this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 #Imports
16 #Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 #Stdlib imports
19 #Stdlib imports
20 from __future__ import print_function
20 from __future__ import print_function
21 import sys
21 import sys
22 import io
22 import io
23 import os
23 import os
24
24
25 #From IPython
25 #From IPython
26 #All the stuff needed for the configurable things
26 #All the stuff needed for the configurable things
27 from IPython.config.application import Application
27 from IPython.config.application import Application
28 from IPython.utils.traitlets import (Bool)
28 from IPython.utils.traitlets import (Bool)
29
29
30 #Local imports
30 #Local imports
31 from nbconvert.export import export_by_name
31 from nbconvert.export import export_by_name
32 from nbconvert.exporters.exporter import Exporter
32 from nbconvert.exporters.exporter import Exporter
33 from nbconvert.transformers import extractfigure
33 from nbconvert.transformers import extractfigure
34
34
35 #-----------------------------------------------------------------------------
35 #-----------------------------------------------------------------------------
36 #Globals and constants
36 #Globals and constants
37 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
38
38
39 #'Keys in resources' user prompt.
39 #'Keys in resources' user prompt.
40 KEYS_PROMPT_HEAD = "====================== Keys in Resources =================================="
40 KEYS_PROMPT_HEAD = "====================== Keys in Resources =================================="
41 KEYS_PROMPT_BODY = """
41 KEYS_PROMPT_BODY = """
42 ===========================================================================
42 ===========================================================================
43 You are responsible for writting these files into the appropriate
43 You are responsible for writting these files into the appropriate
44 directorie(s) if need be. If you do not want to see this message, enable
44 directorie(s) if need be. If you do not want to see this message, enable
45 the 'write' (boolean) flag of the converter.
45 the 'write' (boolean) flag of the converter.
46 ===========================================================================
46 ===========================================================================
47 """
47 """
48
48
49 #-----------------------------------------------------------------------------
49 #-----------------------------------------------------------------------------
50 #Classes and functions
50 #Classes and functions
51 #-----------------------------------------------------------------------------
51 #-----------------------------------------------------------------------------
52
52
53 class NbConvertApp(Application):
53 class NbConvertApp(Application):
54 """Application used to convert to and from notebook file type (*.ipynb)"""
54 """Application used to convert to and from notebook file type (*.ipynb)"""
55
55
56 stdout = Bool(
56 stdout = Bool(
57 True, config=True,
57 True, config=True,
58 help="""Whether to print the converted IPYNB file to stdout
58 help="""Whether to print the converted IPYNB file to stdout
59 use full do diff files without actually writing a new file"""
59 use full do diff files without actually writing a new file"""
60 )
60 )
61
61
62 write = Bool(
62 write = Bool(
63 False, config=True,
63 False, config=True,
64 help="""Should the converted notebook file be written to disk
64 help="""Should the converted notebook file be written to disk
65 along with potential extracted resources."""
65 along with potential extracted resources."""
66 )
66 )
67
67
68
68
69 def __init__(self, **kwargs):
69 def __init__(self, **kwargs):
70 """Public constructor"""
70 """Public constructor"""
71
71
72 #Call base class
72 #Call base class
73 super(NbConvertApp, self).__init__(**kwargs)
73 super(NbConvertApp, self).__init__(**kwargs)
74
74
75 #Register class here to have help with help all
75 #Register class here to have help with help all
76 self.classes.insert(0, Exporter)
76 self.classes.insert(0, Exporter)
77
77
78
78
79 def start(self, argv=None):
79 def start(self, argv=None):
80 """Entrypoint of NbConvert application.
80 """Entrypoint of NbConvert application.
81
81
82 Parameters
82 Parameters
83 ----------
83 ----------
84 argv : list
84 argv : list
85 Commandline arguments
85 Commandline arguments
86 """
86 """
87
87
88 #Parse the commandline options.
88 #Parse the commandline options.
89 self.parse_command_line(argv)
89 self.parse_command_line(argv)
90
90
91 #Call base
91 #Call base
92 super(NbConvertApp, self).start()
92 super(NbConvertApp, self).start()
93
93
94 #The last arguments in list will be used by nbconvert
94 #The last arguments in list will be used by nbconvert
95 export_type = (self.extra_args)[1]
95 export_type = (self.extra_args)[1]
96 ipynb_file = (self.extra_args)[2]
96 ipynb_file = (self.extra_args)[2]
97
97
98 #Export
98 #Export
99 return_value = export_by_name(ipynb_file, export_type)
99 return_value = export_by_name(export_type, ipynb_file)
100 if return_value is None:
100 if return_value is None:
101 print("Error: '%s' template not found." % export_type)
101 print("Error: '%s' template not found." % export_type)
102 return
102 return
103 else:
103 else:
104 (output, resources, exporter) = return_value
104 (output, resources, exporter) = return_value
105
105
106 #TODO: Allow user to set output directory and file.
106 #TODO: Allow user to set output directory and file.
107 destination_filename = None
107 destination_filename = None
108 destination_directory = None
108 destination_directory = None
109 if self.write:
109 if self.write:
110
110
111 #Get the file name without the '.ipynb' (6 chars) extension and then
111 #Get the file name without the '.ipynb' (6 chars) extension and then
112 #remove any addition periods and spaces. The resulting name will
112 #remove any addition periods and spaces. The resulting name will
113 #be used to create the directory that the files will be exported
113 #be used to create the directory that the files will be exported
114 #into.
114 #into.
115 out_root = ipynb_file[:-6].replace('.', '_').replace(' ', '_')
115 out_root = ipynb_file[:-6].replace('.', '_').replace(' ', '_')
116 destination_filename = os.path.join(out_root+'.'+exporter.file_extension)
116 destination_filename = os.path.join(out_root+'.'+exporter.file_extension)
117
117
118 destination_directory = out_root+'_files'
118 destination_directory = out_root+'_files'
119 if not os.path.exists(destination_directory):
119 if not os.path.exists(destination_directory):
120 os.mkdir(destination_directory)
120 os.mkdir(destination_directory)
121
121
122 #Write the results
122 #Write the results
123 if self.stdout or not (destination_filename is None and destination_directory is None):
123 if self.stdout or not (destination_filename is None and destination_directory is None):
124 self._write_results(output, resources, self.stdout, destination_filename, destination_directory)
124 self._write_results(output, resources, self.stdout, destination_filename, destination_directory)
125
125
126
126
127 def _write_results(self, output, resources, stdout=False, destination_filename=None, destination_directory=None):
127 def _write_results(self, output, resources, stdout=False, destination_filename=None, destination_directory=None):
128 """Output the conversion results to the console and/or filesystem
128 """Output the conversion results to the console and/or filesystem
129
129
130 Parameters
130 Parameters
131 ----------
131 ----------
132 output : str
132 output : str
133 Output of conversion
133 Output of conversion
134 resources : dictionary
134 resources : dictionary
135 Additional input/output used by the transformers. For
135 Additional input/output used by the transformers. For
136 example, the ExtractFigure transformer outputs the
136 example, the ExtractFigure transformer outputs the
137 figures it extracts into this dictionary. This method
137 figures it extracts into this dictionary. This method
138 relies on the figures being in this dictionary when
138 relies on the figures being in this dictionary when
139 attempting to write the figures to the file system.
139 attempting to write the figures to the file system.
140 stdout : bool, Optional
140 stdout : bool, Optional
141 Whether or not to echo output to console
141 Whether or not to echo output to console
142 destination_filename : str, Optional
142 destination_filename : str, Optional
143 Filename to write output into. If None, output is not
143 Filename to write output into. If None, output is not
144 written to a file.
144 written to a file.
145 destination_directory : str, Optional
145 destination_directory : str, Optional
146 Directory to write notebook data (i.e. figures) to. If
146 Directory to write notebook data (i.e. figures) to. If
147 None, figures are not written to the file system.
147 None, figures are not written to the file system.
148 """
148 """
149
149
150 if stdout:
150 if stdout:
151 print(output.encode('utf-8'))
151 print(output.encode('utf-8'))
152
152
153 #Write file output from conversion.
153 #Write file output from conversion.
154 if not destination_filename is None:
154 if not destination_filename is None:
155 with io.open(destination_filename, 'w') as f:
155 with io.open(destination_filename, 'w') as f:
156 f.write(output)
156 f.write(output)
157
157
158 #Get the key names used by the extract figure transformer
158 #Get the key names used by the extract figure transformer
159 figures_key = extractfigure.FIGURES_KEY
159 figures_key = extractfigure.FIGURES_KEY
160 binary_key = extractfigure.BINARY_KEY
160 binary_key = extractfigure.BINARY_KEY
161 text_key = extractfigure.TEXT_KEY
161 text_key = extractfigure.TEXT_KEY
162
162
163 #Output any associate figures into the same "root" directory.
163 #Output any associate figures into the same "root" directory.
164 binkeys = resources.get(figures_key, {}).get(binary_key,{}).keys()
164 binkeys = resources.get(figures_key, {}).get(binary_key,{}).keys()
165 textkeys = resources.get(figures_key, {}).get(text_key,{}).keys()
165 textkeys = resources.get(figures_key, {}).get(text_key,{}).keys()
166 if binkeys or textkeys :
166 if binkeys or textkeys :
167 if not destination_directory is None:
167 if not destination_directory is None:
168 for key in binkeys:
168 for key in binkeys:
169 with io.open(os.path.join(destination_directory, key), 'wb') as f:
169 with io.open(os.path.join(destination_directory, key), 'wb') as f:
170 f.write(resources[figures_key][binary_key][key])
170 f.write(resources[figures_key][binary_key][key])
171 for key in textkeys:
171 for key in textkeys:
172 with io.open(os.path.join(destination_directory, key), 'w') as f:
172 with io.open(os.path.join(destination_directory, key), 'w') as f:
173 f.write(resources[figures_key][text_key][key])
173 f.write(resources[figures_key][text_key][key])
174
174
175 #Figures that weren't exported which will need to be created by the
175 #Figures that weren't exported which will need to be created by the
176 #user. Tell the user what figures these are.
176 #user. Tell the user what figures these are.
177 if stdout:
177 if stdout:
178 print(KEYS_PROMPT_HEAD)
178 print(KEYS_PROMPT_HEAD)
179 print(resources[figures_key].keys())
179 print(resources[figures_key].keys())
180 print(KEYS_PROMPT_BODY)
180 print(KEYS_PROMPT_BODY)
181
181
182 #-----------------------------------------------------------------------------
182 #-----------------------------------------------------------------------------
183 #Script main
183 #Script main
184 #-----------------------------------------------------------------------------
184 #-----------------------------------------------------------------------------
185
185
186 def main():
186 def main():
187 """Application entry point"""
187 """Application entry point"""
188
188
189 app = NbConvertApp.instance()
189 app = NbConvertApp.instance()
190 app.description = __doc__
190 app.description = __doc__
191 app.start(argv=sys.argv)
191 app.start(argv=sys.argv)
192
192
193 #Check to see if python is calling this file directly.
193 #Check to see if python is calling this file directly.
194 if __name__ == '__main__':
194 if __name__ == '__main__':
195 main() No newline at end of file
195 main()
@@ -1,483 +1,212
1 """
1 """
2 Module containing single call export functions.
2 Module containing single call export functions.
3 """
3 """
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2013, the IPython Development Team.
5 # Copyright (c) 2013, the IPython Development Team.
6 #
6 #
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8 #
8 #
9 # The full license is in the file COPYING.txt, distributed with this software.
9 # The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15
15
16 import sys
16 import sys
17 import inspect
17 import inspect
18 from functools import wraps
18
19
19 from IPython.nbformat.v3.nbbase import NotebookNode
20 from IPython.nbformat.v3.nbbase import NotebookNode
20
21
21 from .exporters.exporter import Exporter
22 from .exporters.exporter import Exporter
22 from .exporters.basichtml import BasicHtmlExporter
23 from .exporters.basichtml import BasicHtmlExporter
23 from .exporters.fullhtml import FullHtmlExporter
24 from .exporters.fullhtml import FullHtmlExporter
24 from .exporters.latex import LatexExporter
25 from .exporters.latex import LatexExporter
25 from .exporters.markdown import MarkdownExporter
26 from .exporters.markdown import MarkdownExporter
26 from .exporters.python import PythonExporter
27 from .exporters.python import PythonExporter
27 from .exporters.python_armor import PythonArmorExporter
28 from .exporters.python_armor import PythonArmorExporter
28 from .exporters.reveal import RevealExporter
29 from .exporters.reveal import RevealExporter
29 from .exporters.rst import RstExporter
30 from .exporters.rst import RstExporter
30 from .exporters.sphinx_howto import SphinxHowtoExporter
31 from .exporters.sphinx_howto import SphinxHowtoExporter
31 from .exporters.sphinx_manual import SphinxManualExporter
32 from .exporters.sphinx_manual import SphinxManualExporter
32
33
33
34 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
35 # Functions
35 # Classes
36 #-----------------------------------------------------------------------------
36 #-----------------------------------------------------------------------------
37
37
38 def export(nb, config=None, transformers=None, filters=None, exporter_type=Exporter):
38 def DocDecorator(f):
39 """
40 Export a notebook object using specific exporter class.
41
39
42 Parameters
40 #Set docstring of function
43 ----------
41 f.__doc__ = f.__doc__ + """
42 nb : Notebook node
44 config : config
43 config : config
45 User configuration instance.
44 User configuration instance.
46 transformers : list[of transformer]
45 transformers : list[of transformer]
47 Custom transformers to apply to the notebook prior to engaging
46 Custom transformers to apply to the notebook prior to engaging
48 the Jinja template engine. Any transformers specified here
47 the Jinja template engine. Any transformers specified here
49 will override existing transformers if a naming conflict
48 will override existing transformers if a naming conflict
50 occurs.
49 occurs.
51 filters : list[of filter]
50 filters : list[of filter]
52 Custom filters to make accessible to the Jinja templates. Any
51 Custom filters to make accessible to the Jinja templates. Any
53 filters specified here will override existing filters if a
52 filters specified here will override existing filters if a
54 naming conflict occurs.
53 naming conflict occurs.
55 exporter_type:
56 Class type of the exporter that should be used. This method
57 will initialize it's own instance of the class. It is
58 ASSUMED that the class type provided exposes a
59 constructor (__init__) with the same signature as the
60 base Exporter class.
61
54
62 Returns
55 Returns
63 ----------
56 ----------
64 tuple- output, resources, exporter_instance
57 tuple- output, resources, exporter_instance
65 output : str
58 output : str
66 Jinja 2 output. This is the resulting converted notebook.
59 Jinja 2 output. This is the resulting converted notebook.
67 resources : dictionary
60 resources : dictionary
68 Dictionary of resources used prior to and during the conversion
61 Dictionary of resources used prior to and during the conversion
69 process.
62 process.
70 exporter_instance : Exporter
63 exporter_instance : Exporter
71 Instance of the Exporter class used to export the document. Useful
64 Instance of the Exporter class used to export the document. Useful
72 to caller because it provides a 'file_extension' property which
65 to caller because it provides a 'file_extension' property which
73 specifies what extension the output should be saved as.
66 specifies what extension the output should be saved as."""
67
68 @wraps(f)
69 def decorator(*args, **kwargs):
70 return f(*args, **kwargs)
71
72 return decorator
73
74
75 #-----------------------------------------------------------------------------
76 # Functions
77 #-----------------------------------------------------------------------------
78
79 @DocDecorator
80 def export(exporter_type, nb, config=None, transformers=None, filters=None):
81 """
82 Export a notebook object using specific exporter class.
83
84 exporter_type : Exporter class type
85 Class type of the exporter that should be used. This method
86 will initialize it's own instance of the class. It is
87 ASSUMED that the class type provided exposes a
88 constructor (__init__) with the same signature as the
89 base Exporter class.}
74 """
90 """
75
91
76 #Check arguments
92 #Check arguments
77 if exporter_type is None:
93 if exporter_type is None:
78 raise TypeError("Exporter is None")
94 raise TypeError("Exporter is None")
79 elif not issubclass(exporter_type, Exporter):
95 elif not issubclass(exporter_type, Exporter):
80 raise TypeError("Exporter type does not inherit from Exporter (base)")
96 raise TypeError("Exporter type does not inherit from Exporter (base)")
81
97
82 if nb is None:
98 if nb is None:
83 raise TypeError("nb is None")
99 raise TypeError("nb is None")
84
100
85 #Create the exporter
101 #Create the exporter
86 exporter_instance = exporter_type(preprocessors=transformers,
102 exporter_instance = exporter_type(preprocessors=transformers,
87 jinja_filters=filters, config=config)
103 jinja_filters=filters, config=config)
88
104
89 #Try to convert the notebook using the appropriate conversion function.
105 #Try to convert the notebook using the appropriate conversion function.
90 if isinstance(nb, NotebookNode):
106 if isinstance(nb, NotebookNode):
91 output, resources = exporter_instance.from_notebook_node(nb)
107 output, resources = exporter_instance.from_notebook_node(nb)
92 elif isinstance(nb, basestring):
108 elif isinstance(nb, basestring):
93 output, resources = exporter_instance.from_filename(nb)
109 output, resources = exporter_instance.from_filename(nb)
94 else:
110 else:
95 output, resources = exporter_instance.from_file(nb)
111 output, resources = exporter_instance.from_file(nb)
96 return output, resources, exporter_instance
112 return output, resources, exporter_instance
97
113
98
114
115 @DocDecorator
99 def export_sphinx_manual(nb, config=None, transformers=None, filters=None):
116 def export_sphinx_manual(nb, config=None, transformers=None, filters=None):
100 """
117 """
101 Export a notebook object to Sphinx Manual LaTeX
118 Export a notebook object to Sphinx Manual LaTeX
102
103 Parameters
104 ----------
105 config : config
106 User configuration instance.
107 transformers : list[of transformer]
108 Custom transformers to apply to the notebook prior to engaging
109 the Jinja template engine. Any transformers specified here
110 will override existing transformers if a naming conflict
111 occurs.
112 filters : list[of filter]
113 Custom filters to make accessible to the Jinja templates. Any
114 filters specified here will override existing filters if a
115 naming conflict occurs.
116
117 Returns
118 ----------
119 tuple- output, resources, exporter_instance
120 output : str
121 Jinja 2 output. This is the resulting converted notebook.
122 resources : dictionary
123 Dictionary of resources used prior to and during the conversion
124 process.
125 exporter_instance : Exporter
126 Instance of the Exporter class used to export the document. Useful
127 to caller because it provides a 'file_extension' property which
128 specifies what extension the output should be saved as.
129 """
119 """
130 return export(nb, config, transformers, filters, SphinxManualExporter)
120 return export(SphinxManualExporter, nb, config, transformers, filters)
131
121
132
122
123 @DocDecorator
133 def export_sphinx_howto(nb, config=None, transformers=None, filters=None):
124 def export_sphinx_howto(nb, config=None, transformers=None, filters=None):
134 """
125 """
135 Export a notebook object to Sphinx HowTo LaTeX
126 Export a notebook object to Sphinx HowTo LaTeX
136
137 Parameters
138 ----------
139 config : config
140 User configuration instance.
141 transformers : list[of transformer]
142 Custom transformers to apply to the notebook prior to engaging
143 the Jinja template engine. Any transformers specified here
144 will override existing transformers if a naming conflict
145 occurs.
146 filters : list[of filter]
147 Custom filters to make accessible to the Jinja templates. Any
148 filters specified here will override existing filters if a
149 naming conflict occurs.
150
151 Returns
152 ----------
153 tuple- output, resources, exporter_instance
154 output : str
155 Jinja 2 output. This is the resulting converted notebook.
156 resources : dictionary
157 Dictionary of resources used prior to and during the conversion
158 process.
159 exporter_instance : Exporter
160 Instance of the Exporter class used to export the document. Useful
161 to caller because it provides a 'file_extension' property which
162 specifies what extension the output should be saved as.
163 """
127 """
164 return export(nb, config, transformers, filters, SphinxHowtoExporter)
128 return export(SphinxHowtoExporter, nb, config, transformers, filters)
165
129
166
130
131 @DocDecorator
167 def export_basic_html(nb, config=None, transformers=None, filters=None):
132 def export_basic_html(nb, config=None, transformers=None, filters=None):
168 """
133 """
169 Export a notebook object to Basic HTML
134 Export a notebook object to Basic HTML
170
171 Parameters
172 ----------
173 config : config
174 User configuration instance.
175 transformers : list[of transformer]
176 Custom transformers to apply to the notebook prior to engaging
177 the Jinja template engine. Any transformers specified here
178 will override existing transformers if a naming conflict
179 occurs.
180 filters : list[of filter]
181 Custom filters to make accessible to the Jinja templates. Any
182 filters specified here will override existing filters if a
183 naming conflict occurs.
184
185 Returns
186 ----------
187 tuple- output, resources, exporter_instance
188 output : str
189 Jinja 2 output. This is the resulting converted notebook.
190 resources : dictionary
191 Dictionary of resources used prior to and during the conversion
192 process.
193 exporter_instance : Exporter
194 Instance of the Exporter class used to export the document. Useful
195 to caller because it provides a 'file_extension' property which
196 specifies what extension the output should be saved as.
197 """
135 """
198 return export(nb, config, transformers, filters, BasicHtmlExporter)
136 return export(BasicHtmlExporter, nb, config, transformers, filters)
199
137
200
138
139 @DocDecorator
201 def export_full_html(nb, config=None, transformers=None, filters=None):
140 def export_full_html(nb, config=None, transformers=None, filters=None):
202 """
141 """
203 Export a notebook object to Full HTML
142 Export a notebook object to Full HTML
204
205 Parameters
206 ----------
207 config : config
208 User configuration instance.
209 transformers : list[of transformer]
210 Custom transformers to apply to the notebook prior to engaging
211 the Jinja template engine. Any transformers specified here
212 will override existing transformers if a naming conflict
213 occurs.
214 filters : list[of filter]
215 Custom filters to make accessible to the Jinja templates. Any
216 filters specified here will override existing filters if a
217 naming conflict occurs.
218
219 Returns
220 ----------
221 tuple- output, resources, exporter_instance
222 output : str
223 Jinja 2 output. This is the resulting converted notebook.
224 resources : dictionary
225 Dictionary of resources used prior to and during the conversion
226 process.
227 exporter_instance : Exporter
228 Instance of the Exporter class used to export the document. Useful
229 to caller because it provides a 'file_extension' property which
230 specifies what extension the output should be saved as.
231 """
143 """
232 return export(nb, config, transformers, filters, FullHtmlExporter)
144 return export(FullHtmlExporter, nb, config, transformers, filters)
233
145
234
146
147 @DocDecorator
235 def export_latex(nb, config=None, transformers=None, filters=None):
148 def export_latex(nb, config=None, transformers=None, filters=None):
236 """
149 """
237 Export a notebook object to LaTeX
150 Export a notebook object to LaTeX
238
239 Parameters
240 ----------
241 config : config
242 User configuration instance.
243 transformers : list[of transformer]
244 Custom transformers to apply to the notebook prior to engaging
245 the Jinja template engine. Any transformers specified here
246 will override existing transformers if a naming conflict
247 occurs.
248 filters : list[of filter]
249 Custom filters to make accessible to the Jinja templates. Any
250 filters specified here will override existing filters if a
251 naming conflict occurs.
252
253 Returns
254 ----------
255 tuple- output, resources, exporter_instance
256 output : str
257 Jinja 2 output. This is the resulting converted notebook.
258 resources : dictionary
259 Dictionary of resources used prior to and during the conversion
260 process.
261 exporter_instance : Exporter
262 Instance of the Exporter class used to export the document. Useful
263 to caller because it provides a 'file_extension' property which
264 specifies what extension the output should be saved as.
265 """
151 """
266 return export(nb, config, transformers, filters, LatexExporter)
152 return export(LatexExporter, nb, config, transformers, filters)
267
153
268
154
155 @DocDecorator
269 def export_markdown(nb, config=None, transformers=None, filters=None):
156 def export_markdown(nb, config=None, transformers=None, filters=None):
270 """
157 """
271 Export a notebook object to Markdown
158 Export a notebook object to Markdown
272
273 Parameters
274 ----------
275 config : config
276 User configuration instance.
277 transformers : list[of transformer]
278 Custom transformers to apply to the notebook prior to engaging
279 the Jinja template engine. Any transformers specified here
280 will override existing transformers if a naming conflict
281 occurs.
282 filters : list[of filter]
283 Custom filters to make accessible to the Jinja templates. Any
284 filters specified here will override existing filters if a
285 naming conflict occurs.
286
287 Returns
288 ----------
289 tuple- output, resources, exporter_instance
290 output : str
291 Jinja 2 output. This is the resulting converted notebook.
292 resources : dictionary
293 Dictionary of resources used prior to and during the conversion
294 process.
295 exporter_instance : Exporter
296 Instance of the Exporter class used to export the document. Useful
297 to caller because it provides a 'file_extension' property which
298 specifies what extension the output should be saved as.
299 """
159 """
300 return export(nb, config, transformers, filters, MarkdownExporter)
160 return export(MarkdownExporter, nb, config, transformers, filters)
301
161
302
162
163 @DocDecorator
303 def export_python(nb, config=None, transformers=None, filters=None):
164 def export_python(nb, config=None, transformers=None, filters=None):
304 """
165 """
305 Export a notebook object to Python
166 Export a notebook object to Python
306
307 Parameters
308 ----------
309 config : config
310 User configuration instance.
311 transformers : list[of transformer]
312 Custom transformers to apply to the notebook prior to engaging
313 the Jinja template engine. Any transformers specified here
314 will override existing transformers if a naming conflict
315 occurs.
316 filters : list[of filter]
317 Custom filters to make accessible to the Jinja templates. Any
318 filters specified here will override existing filters if a
319 naming conflict occurs.
320
321 Returns
322 ----------
323 tuple- output, resources, exporter_instance
324 output : str
325 Jinja 2 output. This is the resulting converted notebook.
326 resources : dictionary
327 Dictionary of resources used prior to and during the conversion
328 process.
329 exporter_instance : Exporter
330 Instance of the Exporter class used to export the document. Useful
331 to caller because it provides a 'file_extension' property which
332 specifies what extension the output should be saved as.
333 """
167 """
334 return export(nb, config, transformers, filters, PythonExporter)
168 return export(PythonExporter, nb, config, transformers, filters)
335
169
336
170
171 @DocDecorator
337 def export_python_armor(nb, config=None, transformers=None, filters=None):
172 def export_python_armor(nb, config=None, transformers=None, filters=None):
338 """
173 """
339 Export a notebook object to Python (Armor)
174 Export a notebook object to Python (Armor)
340
341 Parameters
342 ----------
343 config : config
344 User configuration instance.
345 transformers : list[of transformer]
346 Custom transformers to apply to the notebook prior to engaging
347 the Jinja template engine. Any transformers specified here
348 will override existing transformers if a naming conflict
349 occurs.
350 filters : list[of filter]
351 Custom filters to make accessible to the Jinja templates. Any
352 filters specified here will override existing filters if a
353 naming conflict occurs.
354
355 Returns
356 ----------
357 tuple- output, resources, exporter_instance
358 output : str
359 Jinja 2 output. This is the resulting converted notebook.
360 resources : dictionary
361 Dictionary of resources used prior to and during the conversion
362 process.
363 exporter_instance : Exporter
364 Instance of the Exporter class used to export the document. Useful
365 to caller because it provides a 'file_extension' property which
366 specifies what extension the output should be saved as.
367 """
175 """
368 return export(nb, config, transformers, filters, PythonArmorExporter)
176 return export(PythonArmorExporter, nb, config, transformers, filters)
369
177
370
178
179 @DocDecorator
371 def export_reveal(nb, config=None, transformers=None, filters=None):
180 def export_reveal(nb, config=None, transformers=None, filters=None):
372 """
181 """
373 Export a notebook object to Reveal
182 Export a notebook object to Reveal
374
375 Parameters
376 ----------
377 config : config
378 User configuration instance.
379 transformers : list[of transformer]
380 Custom transformers to apply to the notebook prior to engaging
381 the Jinja template engine. Any transformers specified here
382 will override existing transformers if a naming conflict
383 occurs.
384 filters : list[of filter]
385 Custom filters to make accessible to the Jinja templates. Any
386 filters specified here will override existing filters if a
387 naming conflict occurs.
388
389 Returns
390 ----------
391 tuple- output, resources, exporter_instance
392 output : str
393 Jinja 2 output. This is the resulting converted notebook.
394 resources : dictionary
395 Dictionary of resources used prior to and during the conversion
396 process.
397 exporter_instance : Exporter
398 Instance of the Exporter class used to export the document. Useful
399 to caller because it provides a 'file_extension' property which
400 specifies what extension the output should be saved as.
401 """
183 """
402 return export(nb, config, transformers, filters, RevealExporter)
184 return export(RevealExporter, nb, config, transformers, filters)
403
185
404
186
187 @DocDecorator
405 def export_rst(nb, config=None, transformers=None, filters=None):
188 def export_rst(nb, config=None, transformers=None, filters=None):
406 """
189 """
407 Export a notebook object to RST
190 Export a notebook object to RST
408
409 Parameters
410 ----------
411 config : config
412 User configuration instance.
413 transformers : list[of transformer]
414 Custom transformers to apply to the notebook prior to engaging
415 the Jinja template engine. Any transformers specified here
416 will override existing transformers if a naming conflict
417 occurs.
418 filters : list[of filter]
419 Custom filters to make accessible to the Jinja templates. Any
420 filters specified here will override existing filters if a
421 naming conflict occurs.
422
423 Returns
424 ----------
425 tuple- output, resources, exporter_instance
426 output : str
427 Jinja 2 output. This is the resulting converted notebook.
428 resources : dictionary
429 Dictionary of resources used prior to and during the conversion
430 process.
431 exporter_instance : Exporter
432 Instance of the Exporter class used to export the document. Useful
433 to caller because it provides a 'file_extension' property which
434 specifies what extension the output should be saved as.
435 """
191 """
436 return export(nb, config, transformers, filters, RstExporter)
192 return export(RstExporter, nb, config, transformers, filters)
437
193
438
194
439 def export_by_name(nb, template_name, config=None, transformers=None, filters=None):
195 @DocDecorator
196 def export_by_name(template_name, nb, config=None, transformers=None, filters=None):
440 """
197 """
441 Export a notebook object to a template type by its name. Reflection
198 Export a notebook object to a template type by its name. Reflection
442 (Inspect) is used to find the template's corresponding explicit export
199 (Inspect) is used to find the template's corresponding explicit export
443 method defined in this module. That method is then called directly.
200 method defined in this module. That method is then called directly.
444
201
445 Parameters
446 ----------
447 template_name : str
202 template_name : str
448 Name of the template style to export to.
203 Name of the template style to export to.
449 config : config
450 User configuration instance.
451 transformers : list[of transformer]
452 Custom transformers to apply to the notebook prior to engaging
453 the Jinja template engine. Any transformers specified here
454 will override existing transformers if a naming conflict
455 occurs.
456 filters : list[of filter]
457 Custom filters to make accessible to the Jinja templates. Any
458 filters specified here will override existing filters if a
459 naming conflict occurs.
460
461 Returns
462 ----------
463 tuple- (output, resources, exporter_instance)
464 None- if template not found
465
466 output : str
467 Jinja 2 output. This is the resulting converted notebook.
468 resources : dictionary
469 Dictionary of resources used prior to and during the conversion
470 process.
471 exporter_instance : Exporter
472 Instance of the Exporter class used to export the document. Useful
473 to caller because it provides a 'file_extension' property which
474 specifies what extension the output should be saved as.
475 """
204 """
476
205
477 function_name = "export_" + template_name.lower()
206 function_name = "export_" + template_name.lower()
478
207
479 if function_name in globals():
208 if function_name in globals():
480 return globals()[function_name](nb, config, transformers, filters)
209 return globals()[function_name](nb, config, transformers, filters)
481 else:
210 else:
482 return None
211 return None
483 No newline at end of file
212
General Comments 0
You need to be logged in to leave comments. Login now