Show More
@@ -1,1 +1,1 b'' | |||||
1 | from export import * No newline at end of file |
|
1 | from exporters.export import * No newline at end of file |
@@ -1,212 +1,212 b'' | |||||
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 | from functools import wraps | |
19 |
|
19 | |||
20 | from IPython.nbformat.v3.nbbase import NotebookNode |
|
20 | from IPython.nbformat.v3.nbbase import NotebookNode | |
21 |
|
21 | |||
22 |
from |
|
22 | from .exporter import Exporter | |
23 |
from |
|
23 | from .basichtml import BasicHtmlExporter | |
24 |
from |
|
24 | from .fullhtml import FullHtmlExporter | |
25 |
from |
|
25 | from .latex import LatexExporter | |
26 |
from |
|
26 | from .markdown import MarkdownExporter | |
27 |
from |
|
27 | from .python import PythonExporter | |
28 |
from |
|
28 | from .python_armor import PythonArmorExporter | |
29 |
from |
|
29 | from .reveal import RevealExporter | |
30 |
from |
|
30 | from .rst import RstExporter | |
31 |
from |
|
31 | from .sphinx_howto import SphinxHowtoExporter | |
32 |
from |
|
32 | from .sphinx_manual import SphinxManualExporter | |
33 |
|
33 | |||
34 | #----------------------------------------------------------------------------- |
|
34 | #----------------------------------------------------------------------------- | |
35 | # Classes |
|
35 | # Classes | |
36 | #----------------------------------------------------------------------------- |
|
36 | #----------------------------------------------------------------------------- | |
37 |
|
37 | |||
38 | def DocDecorator(f): |
|
38 | def DocDecorator(f): | |
39 |
|
39 | |||
40 | #Set docstring of function |
|
40 | #Set docstring of function | |
41 | f.__doc__ = f.__doc__ + """ |
|
41 | f.__doc__ = f.__doc__ + """ | |
42 | nb : Notebook node |
|
42 | nb : Notebook node | |
43 | config : config |
|
43 | config : config | |
44 | User configuration instance. |
|
44 | User configuration instance. | |
45 | transformers : list[of transformer] |
|
45 | transformers : list[of transformer] | |
46 | Custom transformers to apply to the notebook prior to engaging |
|
46 | Custom transformers to apply to the notebook prior to engaging | |
47 | the Jinja template engine. Any transformers specified here |
|
47 | the Jinja template engine. Any transformers specified here | |
48 | will override existing transformers if a naming conflict |
|
48 | will override existing transformers if a naming conflict | |
49 | occurs. |
|
49 | occurs. | |
50 | filters : list[of filter] |
|
50 | filters : list[of filter] | |
51 | Custom filters to make accessible to the Jinja templates. Any |
|
51 | Custom filters to make accessible to the Jinja templates. Any | |
52 | filters specified here will override existing filters if a |
|
52 | filters specified here will override existing filters if a | |
53 | naming conflict occurs. |
|
53 | naming conflict occurs. | |
54 |
|
54 | |||
55 | Returns |
|
55 | Returns | |
56 | ---------- |
|
56 | ---------- | |
57 | tuple- output, resources, exporter_instance |
|
57 | tuple- output, resources, exporter_instance | |
58 | output : str |
|
58 | output : str | |
59 | Jinja 2 output. This is the resulting converted notebook. |
|
59 | Jinja 2 output. This is the resulting converted notebook. | |
60 | resources : dictionary |
|
60 | resources : dictionary | |
61 | Dictionary of resources used prior to and during the conversion |
|
61 | Dictionary of resources used prior to and during the conversion | |
62 | process. |
|
62 | process. | |
63 | exporter_instance : Exporter |
|
63 | exporter_instance : Exporter | |
64 | Instance of the Exporter class used to export the document. Useful |
|
64 | Instance of the Exporter class used to export the document. Useful | |
65 | to caller because it provides a 'file_extension' property which |
|
65 | to caller because it provides a 'file_extension' property which | |
66 | specifies what extension the output should be saved as.""" |
|
66 | specifies what extension the output should be saved as.""" | |
67 |
|
67 | |||
68 | @wraps(f) |
|
68 | @wraps(f) | |
69 | def decorator(*args, **kwargs): |
|
69 | def decorator(*args, **kwargs): | |
70 | return f(*args, **kwargs) |
|
70 | return f(*args, **kwargs) | |
71 |
|
71 | |||
72 | return decorator |
|
72 | return decorator | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | #----------------------------------------------------------------------------- |
|
75 | #----------------------------------------------------------------------------- | |
76 | # Functions |
|
76 | # Functions | |
77 | #----------------------------------------------------------------------------- |
|
77 | #----------------------------------------------------------------------------- | |
78 |
|
78 | |||
79 | @DocDecorator |
|
79 | @DocDecorator | |
80 | def export(exporter_type, nb, config=None, transformers=None, filters=None): |
|
80 | def export(exporter_type, nb, config=None, transformers=None, filters=None): | |
81 | """ |
|
81 | """ | |
82 | Export a notebook object using specific exporter class. |
|
82 | Export a notebook object using specific exporter class. | |
83 |
|
83 | |||
84 | exporter_type : Exporter class type |
|
84 | exporter_type : Exporter class type | |
85 | Class type of the exporter that should be used. This method |
|
85 | Class type of the exporter that should be used. This method | |
86 | will initialize it's own instance of the class. It is |
|
86 | will initialize it's own instance of the class. It is | |
87 | ASSUMED that the class type provided exposes a |
|
87 | ASSUMED that the class type provided exposes a | |
88 | constructor (__init__) with the same signature as the |
|
88 | constructor (__init__) with the same signature as the | |
89 | base Exporter class.} |
|
89 | base Exporter class.} | |
90 | """ |
|
90 | """ | |
91 |
|
91 | |||
92 | #Check arguments |
|
92 | #Check arguments | |
93 | if exporter_type is None: |
|
93 | if exporter_type is None: | |
94 | raise TypeError("Exporter is None") |
|
94 | raise TypeError("Exporter is None") | |
95 | elif not issubclass(exporter_type, Exporter): |
|
95 | elif not issubclass(exporter_type, Exporter): | |
96 | raise TypeError("Exporter type does not inherit from Exporter (base)") |
|
96 | raise TypeError("Exporter type does not inherit from Exporter (base)") | |
97 |
|
97 | |||
98 | if nb is None: |
|
98 | if nb is None: | |
99 | raise TypeError("nb is None") |
|
99 | raise TypeError("nb is None") | |
100 |
|
100 | |||
101 | #Create the exporter |
|
101 | #Create the exporter | |
102 | exporter_instance = exporter_type(preprocessors=transformers, |
|
102 | exporter_instance = exporter_type(preprocessors=transformers, | |
103 | jinja_filters=filters, config=config) |
|
103 | jinja_filters=filters, config=config) | |
104 |
|
104 | |||
105 | #Try to convert the notebook using the appropriate conversion function. |
|
105 | #Try to convert the notebook using the appropriate conversion function. | |
106 | if isinstance(nb, NotebookNode): |
|
106 | if isinstance(nb, NotebookNode): | |
107 | output, resources = exporter_instance.from_notebook_node(nb) |
|
107 | output, resources = exporter_instance.from_notebook_node(nb) | |
108 | elif isinstance(nb, basestring): |
|
108 | elif isinstance(nb, basestring): | |
109 | output, resources = exporter_instance.from_filename(nb) |
|
109 | output, resources = exporter_instance.from_filename(nb) | |
110 | else: |
|
110 | else: | |
111 | output, resources = exporter_instance.from_file(nb) |
|
111 | output, resources = exporter_instance.from_file(nb) | |
112 | return output, resources, exporter_instance |
|
112 | return output, resources, exporter_instance | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | @DocDecorator |
|
115 | @DocDecorator | |
116 | def export_sphinx_manual(nb, config=None, transformers=None, filters=None): |
|
116 | def export_sphinx_manual(nb, config=None, transformers=None, filters=None): | |
117 | """ |
|
117 | """ | |
118 | Export a notebook object to Sphinx Manual LaTeX |
|
118 | Export a notebook object to Sphinx Manual LaTeX | |
119 | """ |
|
119 | """ | |
120 | return export(SphinxManualExporter, nb, config, transformers, filters) |
|
120 | return export(SphinxManualExporter, nb, config, transformers, filters) | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | @DocDecorator |
|
123 | @DocDecorator | |
124 | def export_sphinx_howto(nb, config=None, transformers=None, filters=None): |
|
124 | def export_sphinx_howto(nb, config=None, transformers=None, filters=None): | |
125 | """ |
|
125 | """ | |
126 | Export a notebook object to Sphinx HowTo LaTeX |
|
126 | Export a notebook object to Sphinx HowTo LaTeX | |
127 | """ |
|
127 | """ | |
128 | return export(SphinxHowtoExporter, nb, config, transformers, filters) |
|
128 | return export(SphinxHowtoExporter, nb, config, transformers, filters) | |
129 |
|
129 | |||
130 |
|
130 | |||
131 | @DocDecorator |
|
131 | @DocDecorator | |
132 | def export_basic_html(nb, config=None, transformers=None, filters=None): |
|
132 | def export_basic_html(nb, config=None, transformers=None, filters=None): | |
133 | """ |
|
133 | """ | |
134 | Export a notebook object to Basic HTML |
|
134 | Export a notebook object to Basic HTML | |
135 | """ |
|
135 | """ | |
136 | return export(BasicHtmlExporter, nb, config, transformers, filters) |
|
136 | return export(BasicHtmlExporter, nb, config, transformers, filters) | |
137 |
|
137 | |||
138 |
|
138 | |||
139 | @DocDecorator |
|
139 | @DocDecorator | |
140 | def export_full_html(nb, config=None, transformers=None, filters=None): |
|
140 | def export_full_html(nb, config=None, transformers=None, filters=None): | |
141 | """ |
|
141 | """ | |
142 | Export a notebook object to Full HTML |
|
142 | Export a notebook object to Full HTML | |
143 | """ |
|
143 | """ | |
144 | return export(FullHtmlExporter, nb, config, transformers, filters) |
|
144 | return export(FullHtmlExporter, nb, config, transformers, filters) | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | @DocDecorator |
|
147 | @DocDecorator | |
148 | def export_latex(nb, config=None, transformers=None, filters=None): |
|
148 | def export_latex(nb, config=None, transformers=None, filters=None): | |
149 | """ |
|
149 | """ | |
150 | Export a notebook object to LaTeX |
|
150 | Export a notebook object to LaTeX | |
151 | """ |
|
151 | """ | |
152 | return export(LatexExporter, nb, config, transformers, filters) |
|
152 | return export(LatexExporter, nb, config, transformers, filters) | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | @DocDecorator |
|
155 | @DocDecorator | |
156 | def export_markdown(nb, config=None, transformers=None, filters=None): |
|
156 | def export_markdown(nb, config=None, transformers=None, filters=None): | |
157 | """ |
|
157 | """ | |
158 | Export a notebook object to Markdown |
|
158 | Export a notebook object to Markdown | |
159 | """ |
|
159 | """ | |
160 | return export(MarkdownExporter, nb, config, transformers, filters) |
|
160 | return export(MarkdownExporter, nb, config, transformers, filters) | |
161 |
|
161 | |||
162 |
|
162 | |||
163 | @DocDecorator |
|
163 | @DocDecorator | |
164 | def export_python(nb, config=None, transformers=None, filters=None): |
|
164 | def export_python(nb, config=None, transformers=None, filters=None): | |
165 | """ |
|
165 | """ | |
166 | Export a notebook object to Python |
|
166 | Export a notebook object to Python | |
167 | """ |
|
167 | """ | |
168 | return export(PythonExporter, nb, config, transformers, filters) |
|
168 | return export(PythonExporter, nb, config, transformers, filters) | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | @DocDecorator |
|
171 | @DocDecorator | |
172 | def export_python_armor(nb, config=None, transformers=None, filters=None): |
|
172 | def export_python_armor(nb, config=None, transformers=None, filters=None): | |
173 | """ |
|
173 | """ | |
174 | Export a notebook object to Python (Armor) |
|
174 | Export a notebook object to Python (Armor) | |
175 | """ |
|
175 | """ | |
176 | return export(PythonArmorExporter, nb, config, transformers, filters) |
|
176 | return export(PythonArmorExporter, nb, config, transformers, filters) | |
177 |
|
177 | |||
178 |
|
178 | |||
179 | @DocDecorator |
|
179 | @DocDecorator | |
180 | def export_reveal(nb, config=None, transformers=None, filters=None): |
|
180 | def export_reveal(nb, config=None, transformers=None, filters=None): | |
181 | """ |
|
181 | """ | |
182 | Export a notebook object to Reveal |
|
182 | Export a notebook object to Reveal | |
183 | """ |
|
183 | """ | |
184 | return export(RevealExporter, nb, config, transformers, filters) |
|
184 | return export(RevealExporter, nb, config, transformers, filters) | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | @DocDecorator |
|
187 | @DocDecorator | |
188 | def export_rst(nb, config=None, transformers=None, filters=None): |
|
188 | def export_rst(nb, config=None, transformers=None, filters=None): | |
189 | """ |
|
189 | """ | |
190 | Export a notebook object to RST |
|
190 | Export a notebook object to RST | |
191 | """ |
|
191 | """ | |
192 | return export(RstExporter, nb, config, transformers, filters) |
|
192 | return export(RstExporter, nb, config, transformers, filters) | |
193 |
|
193 | |||
194 |
|
194 | |||
195 | @DocDecorator |
|
195 | @DocDecorator | |
196 | def export_by_name(template_name, nb, config=None, transformers=None, filters=None): |
|
196 | def export_by_name(template_name, nb, config=None, transformers=None, filters=None): | |
197 | """ |
|
197 | """ | |
198 | 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 | |
199 | (Inspect) is used to find the template's corresponding explicit export |
|
199 | (Inspect) is used to find the template's corresponding explicit export | |
200 | method defined in this module. That method is then called directly. |
|
200 | method defined in this module. That method is then called directly. | |
201 |
|
201 | |||
202 | template_name : str |
|
202 | template_name : str | |
203 | Name of the template style to export to. |
|
203 | Name of the template style to export to. | |
204 | """ |
|
204 | """ | |
205 |
|
205 | |||
206 | function_name = "export_" + template_name.lower() |
|
206 | function_name = "export_" + template_name.lower() | |
207 |
|
207 | |||
208 | if function_name in globals(): |
|
208 | if function_name in globals(): | |
209 | return globals()[function_name](nb, config, transformers, filters) |
|
209 | return globals()[function_name](nb, config, transformers, filters) | |
210 | else: |
|
210 | else: | |
211 | return None |
|
211 | return None | |
212 | No newline at end of file |
|
212 |
General Comments 0
You need to be logged in to leave comments.
Login now