Show More
@@ -1,10 +1,10 b'' | |||||
1 |
from .basichtml import BasicH |
|
1 | from .basichtml import BasicHTMLExporter | |
2 | from .export import * |
|
2 | from .export import * | |
3 | from .exporter import Exporter |
|
3 | from .exporter import Exporter | |
4 |
from .fullhtml import FullH |
|
4 | from .fullhtml import FullHTMLExporter | |
5 | from .latex import LatexExporter |
|
5 | from .latex import LatexExporter | |
6 | from .markdown import MarkdownExporter |
|
6 | from .markdown import MarkdownExporter | |
7 | from .python import PythonExporter |
|
7 | from .python import PythonExporter | |
8 | from .rst import RstExporter |
|
8 | from .rst import RstExporter | |
9 | from .sphinx_howto import SphinxHowtoExporter |
|
9 | from .sphinx_howto import SphinxHowtoExporter | |
10 | from .sphinx_manual import SphinxManualExporter |
|
10 | from .sphinx_manual import SphinxManualExporter |
@@ -1,55 +1,55 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Exporter that exports Basic HTML. |
|
2 | Exporter that exports Basic HTML. | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | from IPython.utils.traitlets import Unicode |
|
17 | from IPython.utils.traitlets import Unicode | |
18 |
|
18 | |||
19 |
from ..transformers.csshtmlheader import CSSH |
|
19 | from ..transformers.csshtmlheader import CSSHTMLHeaderTransformer | |
20 |
|
20 | |||
21 | from .exporter import Exporter |
|
21 | from .exporter import Exporter | |
22 |
|
22 | |||
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 | # Classes |
|
24 | # Classes | |
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 |
|
26 | |||
27 |
class BasicH |
|
27 | class BasicHTMLExporter(Exporter): | |
28 | """ |
|
28 | """ | |
29 | Exports a basic HTML document. This exporter assists with the export of |
|
29 | Exports a basic HTML document. This exporter assists with the export of | |
30 | HTML. Inherit from it if you are writing your own HTML template and need |
|
30 | HTML. Inherit from it if you are writing your own HTML template and need | |
31 | custom transformers/filters. If you don't need custom transformers/ |
|
31 | custom transformers/filters. If you don't need custom transformers/ | |
32 | filters, just change the 'template_file' config option. |
|
32 | filters, just change the 'template_file' config option. | |
33 | """ |
|
33 | """ | |
34 |
|
34 | |||
35 | file_extension = Unicode( |
|
35 | file_extension = Unicode( | |
36 | 'html', config=True, |
|
36 | 'html', config=True, | |
37 | help="Extension of the file that should be written to disk" |
|
37 | help="Extension of the file that should be written to disk" | |
38 | ) |
|
38 | ) | |
39 |
|
39 | |||
40 | template_file = Unicode( |
|
40 | template_file = Unicode( | |
41 | 'basichtml', config=True, |
|
41 | 'basichtml', config=True, | |
42 | help="Name of the template file to use") |
|
42 | help="Name of the template file to use") | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | def _register_transformers(self): |
|
45 | def _register_transformers(self): | |
46 | """ |
|
46 | """ | |
47 | Register all of the transformers needed for this exporter. |
|
47 | Register all of the transformers needed for this exporter. | |
48 | """ |
|
48 | """ | |
49 |
|
49 | |||
50 | #Register the transformers of the base class. |
|
50 | #Register the transformers of the base class. | |
51 |
super(BasicH |
|
51 | super(BasicHTMLExporter, self)._register_transformers() | |
52 |
|
52 | |||
53 |
#Register CSSH |
|
53 | #Register CSSHTMLHeaderTransformer transformer | |
54 |
self.register_transformer(CSSH |
|
54 | self.register_transformer(CSSHTMLHeaderTransformer) | |
55 |
|
55 |
@@ -1,225 +1,225 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 | from functools import wraps |
|
16 | from functools import wraps | |
17 |
|
17 | |||
18 | from IPython.nbformat.v3.nbbase import NotebookNode |
|
18 | from IPython.nbformat.v3.nbbase import NotebookNode | |
19 |
|
19 | |||
20 | from .exporter import Exporter |
|
20 | from .exporter import Exporter | |
21 |
from .basichtml import BasicH |
|
21 | from .basichtml import BasicHTMLExporter | |
22 |
from .fullhtml import FullH |
|
22 | from .fullhtml import FullHTMLExporter | |
23 | from .latex import LatexExporter |
|
23 | from .latex import LatexExporter | |
24 | from .markdown import MarkdownExporter |
|
24 | from .markdown import MarkdownExporter | |
25 | from .python import PythonExporter |
|
25 | from .python import PythonExporter | |
26 | from .python_armor import PythonArmorExporter |
|
26 | from .python_armor import PythonArmorExporter | |
27 | from .reveal import RevealExporter |
|
27 | from .reveal import RevealExporter | |
28 | from .rst import RstExporter |
|
28 | from .rst import RstExporter | |
29 | from .sphinx_howto import SphinxHowtoExporter |
|
29 | from .sphinx_howto import SphinxHowtoExporter | |
30 | from .sphinx_manual import SphinxManualExporter |
|
30 | from .sphinx_manual import SphinxManualExporter | |
31 |
|
31 | |||
32 | #----------------------------------------------------------------------------- |
|
32 | #----------------------------------------------------------------------------- | |
33 | # Classes |
|
33 | # Classes | |
34 | #----------------------------------------------------------------------------- |
|
34 | #----------------------------------------------------------------------------- | |
35 |
|
35 | |||
36 | def DocDecorator(f): |
|
36 | def DocDecorator(f): | |
37 |
|
37 | |||
38 | #Set docstring of function |
|
38 | #Set docstring of function | |
39 | f.__doc__ = f.__doc__ + """ |
|
39 | f.__doc__ = f.__doc__ + """ | |
40 | nb : Notebook node |
|
40 | nb : Notebook node | |
41 | config : config |
|
41 | config : config | |
42 | User configuration instance. |
|
42 | User configuration instance. | |
43 | transformers : list[of transformer] |
|
43 | transformers : list[of transformer] | |
44 | Custom transformers to apply to the notebook prior to engaging |
|
44 | Custom transformers to apply to the notebook prior to engaging | |
45 | the Jinja template engine. Any transformers specified here |
|
45 | the Jinja template engine. Any transformers specified here | |
46 | will override existing transformers if a naming conflict |
|
46 | will override existing transformers if a naming conflict | |
47 | occurs. |
|
47 | occurs. | |
48 | filters : list[of filter] |
|
48 | filters : list[of filter] | |
49 | Custom filters to make accessible to the Jinja templates. Any |
|
49 | Custom filters to make accessible to the Jinja templates. Any | |
50 | filters specified here will override existing filters if a |
|
50 | filters specified here will override existing filters if a | |
51 | naming conflict occurs. |
|
51 | naming conflict occurs. | |
52 |
|
52 | |||
53 | Returns |
|
53 | Returns | |
54 | ---------- |
|
54 | ---------- | |
55 | tuple- output, resources, exporter_instance |
|
55 | tuple- output, resources, exporter_instance | |
56 | output : str |
|
56 | output : str | |
57 | Jinja 2 output. This is the resulting converted notebook. |
|
57 | Jinja 2 output. This is the resulting converted notebook. | |
58 | resources : dictionary |
|
58 | resources : dictionary | |
59 | Dictionary of resources used prior to and during the conversion |
|
59 | Dictionary of resources used prior to and during the conversion | |
60 | process. |
|
60 | process. | |
61 | exporter_instance : Exporter |
|
61 | exporter_instance : Exporter | |
62 | Instance of the Exporter class used to export the document. Useful |
|
62 | Instance of the Exporter class used to export the document. Useful | |
63 | to caller because it provides a 'file_extension' property which |
|
63 | to caller because it provides a 'file_extension' property which | |
64 | specifies what extension the output should be saved as.""" |
|
64 | specifies what extension the output should be saved as.""" | |
65 |
|
65 | |||
66 | @wraps(f) |
|
66 | @wraps(f) | |
67 | def decorator(*args, **kwargs): |
|
67 | def decorator(*args, **kwargs): | |
68 | return f(*args, **kwargs) |
|
68 | return f(*args, **kwargs) | |
69 |
|
69 | |||
70 | return decorator |
|
70 | return decorator | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | #----------------------------------------------------------------------------- |
|
73 | #----------------------------------------------------------------------------- | |
74 | # Functions |
|
74 | # Functions | |
75 | #----------------------------------------------------------------------------- |
|
75 | #----------------------------------------------------------------------------- | |
76 |
|
76 | |||
77 | __all__ = [ |
|
77 | __all__ = [ | |
78 | 'export', |
|
78 | 'export', | |
79 | 'export_sphinx_manual', |
|
79 | 'export_sphinx_manual', | |
80 | 'export_sphinx_howto', |
|
80 | 'export_sphinx_howto', | |
81 | 'export_basic_html', |
|
81 | 'export_basic_html', | |
82 | 'export_full_html', |
|
82 | 'export_full_html', | |
83 | 'export_latex', |
|
83 | 'export_latex', | |
84 | 'export_markdown', |
|
84 | 'export_markdown', | |
85 | 'export_python', |
|
85 | 'export_python', | |
86 | 'export_python_armor', |
|
86 | 'export_python_armor', | |
87 | 'export_reveal', |
|
87 | 'export_reveal', | |
88 | 'export_rst', |
|
88 | 'export_rst', | |
89 | 'export_by_name' |
|
89 | 'export_by_name' | |
90 | ] |
|
90 | ] | |
91 |
|
91 | |||
92 | @DocDecorator |
|
92 | @DocDecorator | |
93 | def export(exporter_type, nb, config=None, transformers=None, filters=None): |
|
93 | def export(exporter_type, nb, config=None, transformers=None, filters=None): | |
94 | """ |
|
94 | """ | |
95 | Export a notebook object using specific exporter class. |
|
95 | Export a notebook object using specific exporter class. | |
96 |
|
96 | |||
97 | exporter_type : Exporter class type |
|
97 | exporter_type : Exporter class type | |
98 | Class type of the exporter that should be used. This method |
|
98 | Class type of the exporter that should be used. This method | |
99 | will initialize it's own instance of the class. It is |
|
99 | will initialize it's own instance of the class. It is | |
100 | ASSUMED that the class type provided exposes a |
|
100 | ASSUMED that the class type provided exposes a | |
101 | constructor (__init__) with the same signature as the |
|
101 | constructor (__init__) with the same signature as the | |
102 | base Exporter class.} |
|
102 | base Exporter class.} | |
103 | """ |
|
103 | """ | |
104 |
|
104 | |||
105 | #Check arguments |
|
105 | #Check arguments | |
106 | if exporter_type is None: |
|
106 | if exporter_type is None: | |
107 | raise TypeError("Exporter is None") |
|
107 | raise TypeError("Exporter is None") | |
108 | elif not issubclass(exporter_type, Exporter): |
|
108 | elif not issubclass(exporter_type, Exporter): | |
109 | raise TypeError("Exporter type does not inherit from Exporter (base)") |
|
109 | raise TypeError("Exporter type does not inherit from Exporter (base)") | |
110 |
|
110 | |||
111 | if nb is None: |
|
111 | if nb is None: | |
112 | raise TypeError("nb is None") |
|
112 | raise TypeError("nb is None") | |
113 |
|
113 | |||
114 | #Create the exporter |
|
114 | #Create the exporter | |
115 | exporter_instance = exporter_type(preprocessors=transformers, |
|
115 | exporter_instance = exporter_type(preprocessors=transformers, | |
116 | jinja_filters=filters, config=config) |
|
116 | jinja_filters=filters, config=config) | |
117 |
|
117 | |||
118 | #Try to convert the notebook using the appropriate conversion function. |
|
118 | #Try to convert the notebook using the appropriate conversion function. | |
119 | if isinstance(nb, NotebookNode): |
|
119 | if isinstance(nb, NotebookNode): | |
120 | output, resources = exporter_instance.from_notebook_node(nb) |
|
120 | output, resources = exporter_instance.from_notebook_node(nb) | |
121 | elif isinstance(nb, basestring): |
|
121 | elif isinstance(nb, basestring): | |
122 | output, resources = exporter_instance.from_filename(nb) |
|
122 | output, resources = exporter_instance.from_filename(nb) | |
123 | else: |
|
123 | else: | |
124 | output, resources = exporter_instance.from_file(nb) |
|
124 | output, resources = exporter_instance.from_file(nb) | |
125 | return output, resources, exporter_instance |
|
125 | return output, resources, exporter_instance | |
126 |
|
126 | |||
127 |
|
127 | |||
128 | @DocDecorator |
|
128 | @DocDecorator | |
129 | def export_sphinx_manual(nb, config=None, transformers=None, filters=None): |
|
129 | def export_sphinx_manual(nb, config=None, transformers=None, filters=None): | |
130 | """ |
|
130 | """ | |
131 | Export a notebook object to Sphinx Manual LaTeX |
|
131 | Export a notebook object to Sphinx Manual LaTeX | |
132 | """ |
|
132 | """ | |
133 | return export(SphinxManualExporter, nb, config, transformers, filters) |
|
133 | return export(SphinxManualExporter, nb, config, transformers, filters) | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | @DocDecorator |
|
136 | @DocDecorator | |
137 | def export_sphinx_howto(nb, config=None, transformers=None, filters=None): |
|
137 | def export_sphinx_howto(nb, config=None, transformers=None, filters=None): | |
138 | """ |
|
138 | """ | |
139 | Export a notebook object to Sphinx HowTo LaTeX |
|
139 | Export a notebook object to Sphinx HowTo LaTeX | |
140 | """ |
|
140 | """ | |
141 | return export(SphinxHowtoExporter, nb, config, transformers, filters) |
|
141 | return export(SphinxHowtoExporter, nb, config, transformers, filters) | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | @DocDecorator |
|
144 | @DocDecorator | |
145 | def export_basic_html(nb, config=None, transformers=None, filters=None): |
|
145 | def export_basic_html(nb, config=None, transformers=None, filters=None): | |
146 | """ |
|
146 | """ | |
147 | Export a notebook object to Basic HTML |
|
147 | Export a notebook object to Basic HTML | |
148 | """ |
|
148 | """ | |
149 |
return export(BasicH |
|
149 | return export(BasicHTMLExporter, nb, config, transformers, filters) | |
150 |
|
150 | |||
151 |
|
151 | |||
152 | @DocDecorator |
|
152 | @DocDecorator | |
153 | def export_full_html(nb, config=None, transformers=None, filters=None): |
|
153 | def export_full_html(nb, config=None, transformers=None, filters=None): | |
154 | """ |
|
154 | """ | |
155 | Export a notebook object to Full HTML |
|
155 | Export a notebook object to Full HTML | |
156 | """ |
|
156 | """ | |
157 |
return export(FullH |
|
157 | return export(FullHTMLExporter, nb, config, transformers, filters) | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | @DocDecorator |
|
160 | @DocDecorator | |
161 | def export_latex(nb, config=None, transformers=None, filters=None): |
|
161 | def export_latex(nb, config=None, transformers=None, filters=None): | |
162 | """ |
|
162 | """ | |
163 | Export a notebook object to LaTeX |
|
163 | Export a notebook object to LaTeX | |
164 | """ |
|
164 | """ | |
165 | return export(LatexExporter, nb, config, transformers, filters) |
|
165 | return export(LatexExporter, nb, config, transformers, filters) | |
166 |
|
166 | |||
167 |
|
167 | |||
168 | @DocDecorator |
|
168 | @DocDecorator | |
169 | def export_markdown(nb, config=None, transformers=None, filters=None): |
|
169 | def export_markdown(nb, config=None, transformers=None, filters=None): | |
170 | """ |
|
170 | """ | |
171 | Export a notebook object to Markdown |
|
171 | Export a notebook object to Markdown | |
172 | """ |
|
172 | """ | |
173 | return export(MarkdownExporter, nb, config, transformers, filters) |
|
173 | return export(MarkdownExporter, nb, config, transformers, filters) | |
174 |
|
174 | |||
175 |
|
175 | |||
176 | @DocDecorator |
|
176 | @DocDecorator | |
177 | def export_python(nb, config=None, transformers=None, filters=None): |
|
177 | def export_python(nb, config=None, transformers=None, filters=None): | |
178 | """ |
|
178 | """ | |
179 | Export a notebook object to Python |
|
179 | Export a notebook object to Python | |
180 | """ |
|
180 | """ | |
181 | return export(PythonExporter, nb, config, transformers, filters) |
|
181 | return export(PythonExporter, nb, config, transformers, filters) | |
182 |
|
182 | |||
183 |
|
183 | |||
184 | @DocDecorator |
|
184 | @DocDecorator | |
185 | def export_python_armor(nb, config=None, transformers=None, filters=None): |
|
185 | def export_python_armor(nb, config=None, transformers=None, filters=None): | |
186 | """ |
|
186 | """ | |
187 | Export a notebook object to Python (Armor) |
|
187 | Export a notebook object to Python (Armor) | |
188 | """ |
|
188 | """ | |
189 | return export(PythonArmorExporter, nb, config, transformers, filters) |
|
189 | return export(PythonArmorExporter, nb, config, transformers, filters) | |
190 |
|
190 | |||
191 |
|
191 | |||
192 | @DocDecorator |
|
192 | @DocDecorator | |
193 | def export_reveal(nb, config=None, transformers=None, filters=None): |
|
193 | def export_reveal(nb, config=None, transformers=None, filters=None): | |
194 | """ |
|
194 | """ | |
195 | Export a notebook object to Reveal |
|
195 | Export a notebook object to Reveal | |
196 | """ |
|
196 | """ | |
197 | return export(RevealExporter, nb, config, transformers, filters) |
|
197 | return export(RevealExporter, nb, config, transformers, filters) | |
198 |
|
198 | |||
199 |
|
199 | |||
200 | @DocDecorator |
|
200 | @DocDecorator | |
201 | def export_rst(nb, config=None, transformers=None, filters=None): |
|
201 | def export_rst(nb, config=None, transformers=None, filters=None): | |
202 | """ |
|
202 | """ | |
203 | Export a notebook object to RST |
|
203 | Export a notebook object to RST | |
204 | """ |
|
204 | """ | |
205 | return export(RstExporter, nb, config, transformers, filters) |
|
205 | return export(RstExporter, nb, config, transformers, filters) | |
206 |
|
206 | |||
207 |
|
207 | |||
208 | @DocDecorator |
|
208 | @DocDecorator | |
209 | def export_by_name(template_name, nb, config=None, transformers=None, filters=None): |
|
209 | def export_by_name(template_name, nb, config=None, transformers=None, filters=None): | |
210 | """ |
|
210 | """ | |
211 | Export a notebook object to a template type by its name. Reflection |
|
211 | Export a notebook object to a template type by its name. Reflection | |
212 | (Inspect) is used to find the template's corresponding explicit export |
|
212 | (Inspect) is used to find the template's corresponding explicit export | |
213 | method defined in this module. That method is then called directly. |
|
213 | method defined in this module. That method is then called directly. | |
214 |
|
214 | |||
215 | template_name : str |
|
215 | template_name : str | |
216 | Name of the template style to export to. |
|
216 | Name of the template style to export to. | |
217 | """ |
|
217 | """ | |
218 |
|
218 | |||
219 | function_name = "export_" + template_name.lower() |
|
219 | function_name = "export_" + template_name.lower() | |
220 |
|
220 | |||
221 | if function_name in globals(): |
|
221 | if function_name in globals(): | |
222 | return globals()[function_name](nb, config, transformers, filters) |
|
222 | return globals()[function_name](nb, config, transformers, filters) | |
223 | else: |
|
223 | else: | |
224 | return None |
|
224 | return None | |
225 |
|
225 |
@@ -1,39 +1,39 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Exporter for exporting full HTML documents. |
|
2 | Exporter for exporting full HTML documents. | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | from IPython.utils.traitlets import Unicode |
|
17 | from IPython.utils.traitlets import Unicode | |
18 |
|
18 | |||
19 |
from .basichtml import BasicH |
|
19 | from .basichtml import BasicHTMLExporter | |
20 | from IPython.config import Config |
|
20 | from IPython.config import Config | |
21 |
|
21 | |||
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | # Classes |
|
23 | # Classes | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 |
class FullH |
|
26 | class FullHTMLExporter(BasicHTMLExporter): | |
27 | """ |
|
27 | """ | |
28 | Exports a full HTML document. |
|
28 | Exports a full HTML document. | |
29 | """ |
|
29 | """ | |
30 |
|
30 | |||
31 | template_file = Unicode( |
|
31 | template_file = Unicode( | |
32 | 'fullhtml', config=True, |
|
32 | 'fullhtml', config=True, | |
33 | help="Name of the template file to use") |
|
33 | help="Name of the template file to use") | |
34 |
|
34 | |||
35 | @property |
|
35 | @property | |
36 | def default_config(self): |
|
36 | def default_config(self): | |
37 |
c = Config({'CSSH |
|
37 | c = Config({'CSSHTMLHeaderTransformer':{'enabled':True}}) | |
38 |
c.merge(super(FullH |
|
38 | c.merge(super(FullHTMLExporter,self).default_config) | |
39 | return c |
|
39 | return c |
@@ -1,54 +1,54 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Reveal slide show exporter. |
|
2 | Reveal slide show exporter. | |
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 | from IPython.utils.traitlets import Unicode |
|
16 | from IPython.utils.traitlets import Unicode | |
17 | from IPython.config import Config |
|
17 | from IPython.config import Config | |
18 |
|
18 | |||
19 |
from .basichtml import BasicH |
|
19 | from .basichtml import BasicHTMLExporter | |
20 | from IPython.nbconvert import transformers |
|
20 | from IPython.nbconvert import transformers | |
21 |
|
21 | |||
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | # Classes |
|
23 | # Classes | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 |
class RevealExporter(BasicH |
|
26 | class RevealExporter(BasicHTMLExporter): | |
27 | """ |
|
27 | """ | |
28 | Exports a Reveal slide show (.HTML) which may be rendered in a web browser. |
|
28 | Exports a Reveal slide show (.HTML) which may be rendered in a web browser. | |
29 | """ |
|
29 | """ | |
30 |
|
30 | |||
31 | file_extension = Unicode( |
|
31 | file_extension = Unicode( | |
32 | 'reveal.html', config=True, |
|
32 | 'reveal.html', config=True, | |
33 | help="Extension of the file that should be written to disk") |
|
33 | help="Extension of the file that should be written to disk") | |
34 |
|
34 | |||
35 | template_file = Unicode( |
|
35 | template_file = Unicode( | |
36 | 'reveal', config=True, |
|
36 | 'reveal', config=True, | |
37 | help="Name of the template file to use") |
|
37 | help="Name of the template file to use") | |
38 |
|
38 | |||
39 | def _register_transformers(self): |
|
39 | def _register_transformers(self): | |
40 | """ |
|
40 | """ | |
41 | Register all of the transformers needed for this exporter. |
|
41 | Register all of the transformers needed for this exporter. | |
42 | """ |
|
42 | """ | |
43 |
|
43 | |||
44 | #Register the transformers of the base class. |
|
44 | #Register the transformers of the base class. | |
45 | super(RevealExporter, self)._register_transformers() |
|
45 | super(RevealExporter, self)._register_transformers() | |
46 |
|
46 | |||
47 | #Register reveal help transformer |
|
47 | #Register reveal help transformer | |
48 | self.register_transformer(transformers.RevealHelpTransformer) |
|
48 | self.register_transformer(transformers.RevealHelpTransformer) | |
49 |
|
49 | |||
50 | @property |
|
50 | @property | |
51 | def default_config(self): |
|
51 | def default_config(self): | |
52 |
c = Config({'CSSH |
|
52 | c = Config({'CSSHTMLHeaderTransformer':{'enabled':True}}) | |
53 | c.merge(super(RevealExporter,self).default_config) |
|
53 | c.merge(super(RevealExporter,self).default_config) | |
54 | return c |
|
54 | return c |
@@ -1,105 +1,105 b'' | |||||
1 | """Module that pre-processes the notebook for export to HTML. |
|
1 | """Module that pre-processes the notebook for export to HTML. | |
2 | """ |
|
2 | """ | |
3 | #----------------------------------------------------------------------------- |
|
3 | #----------------------------------------------------------------------------- | |
4 | # Copyright (c) 2013, the IPython Development Team. |
|
4 | # Copyright (c) 2013, the IPython Development Team. | |
5 | # |
|
5 | # | |
6 | # Distributed under the terms of the Modified BSD License. |
|
6 | # Distributed under the terms of the Modified BSD License. | |
7 | # |
|
7 | # | |
8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
8 | # The full license is in the file COPYING.txt, distributed with this software. | |
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 |
|
10 | |||
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 | # Imports |
|
12 | # Imports | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | import os |
|
15 | import os | |
16 | import io |
|
16 | import io | |
17 |
|
17 | |||
18 | from pygments.formatters import HtmlFormatter |
|
18 | from pygments.formatters import HtmlFormatter | |
19 |
|
19 | |||
20 | from IPython.utils import path |
|
20 | from IPython.utils import path | |
21 |
|
21 | |||
22 | from .activatable import ActivatableTransformer |
|
22 | from .activatable import ActivatableTransformer | |
23 |
|
23 | |||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | # Classes and functions |
|
25 | # Classes and functions | |
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
27 |
|
27 | |||
28 |
class CSSH |
|
28 | class CSSHTMLHeaderTransformer(ActivatableTransformer): | |
29 | """ |
|
29 | """ | |
30 | Transformer used to pre-process notebook for HTML output. Adds IPython notebook |
|
30 | Transformer used to pre-process notebook for HTML output. Adds IPython notebook | |
31 | front-end CSS and Pygments CSS to HTML output. |
|
31 | front-end CSS and Pygments CSS to HTML output. | |
32 | """ |
|
32 | """ | |
33 |
|
33 | |||
34 | header = [] |
|
34 | header = [] | |
35 |
|
35 | |||
36 | def __init__(self, config=None, **kw): |
|
36 | def __init__(self, config=None, **kw): | |
37 | """ |
|
37 | """ | |
38 | Public constructor |
|
38 | Public constructor | |
39 |
|
39 | |||
40 | Parameters |
|
40 | Parameters | |
41 | ---------- |
|
41 | ---------- | |
42 | config : Config |
|
42 | config : Config | |
43 | Configuration file structure |
|
43 | Configuration file structure | |
44 | **kw : misc |
|
44 | **kw : misc | |
45 | Additional arguments |
|
45 | Additional arguments | |
46 | """ |
|
46 | """ | |
47 |
|
47 | |||
48 |
super(CSSH |
|
48 | super(CSSHTMLHeaderTransformer, self).__init__(config=config, **kw) | |
49 |
|
49 | |||
50 | if self.enabled : |
|
50 | if self.enabled : | |
51 | self._regen_header() |
|
51 | self._regen_header() | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | def __call__(self, nb, resources): |
|
54 | def __call__(self, nb, resources): | |
55 | """Fetch and add CSS to the resource dictionary |
|
55 | """Fetch and add CSS to the resource dictionary | |
56 |
|
56 | |||
57 | Fetch CSS from IPython and Pygments to add at the beginning |
|
57 | Fetch CSS from IPython and Pygments to add at the beginning | |
58 | of the html files. Add this css in resources in the |
|
58 | of the html files. Add this css in resources in the | |
59 | "inlining.css" key |
|
59 | "inlining.css" key | |
60 |
|
60 | |||
61 | Parameters |
|
61 | Parameters | |
62 | ---------- |
|
62 | ---------- | |
63 | nb : NotebookNode |
|
63 | nb : NotebookNode | |
64 | Notebook being converted |
|
64 | Notebook being converted | |
65 | resources : dictionary |
|
65 | resources : dictionary | |
66 | Additional resources used in the conversion process. Allows |
|
66 | Additional resources used in the conversion process. Allows | |
67 | transformers to pass variables into the Jinja engine. |
|
67 | transformers to pass variables into the Jinja engine. | |
68 | """ |
|
68 | """ | |
69 |
|
69 | |||
70 | resources['inlining'] = {} |
|
70 | resources['inlining'] = {} | |
71 | resources['inlining']['css'] = self.header |
|
71 | resources['inlining']['css'] = self.header | |
72 |
|
72 | |||
73 | return nb, resources |
|
73 | return nb, resources | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | def _regen_header(self): |
|
76 | def _regen_header(self): | |
77 | """ |
|
77 | """ | |
78 | Fills self.header with lines of CSS extracted from IPython |
|
78 | Fills self.header with lines of CSS extracted from IPython | |
79 | and Pygments. |
|
79 | and Pygments. | |
80 | """ |
|
80 | """ | |
81 |
|
81 | |||
82 | #Clear existing header. |
|
82 | #Clear existing header. | |
83 | header = [] |
|
83 | header = [] | |
84 |
|
84 | |||
85 | #Construct path to IPy CSS |
|
85 | #Construct path to IPy CSS | |
86 | sheet_filename = os.path.join(path.get_ipython_package_dir(), |
|
86 | sheet_filename = os.path.join(path.get_ipython_package_dir(), | |
87 | 'html', 'static', 'style', 'style.min.css') |
|
87 | 'html', 'static', 'style', 'style.min.css') | |
88 |
|
88 | |||
89 | #Load style CSS file. |
|
89 | #Load style CSS file. | |
90 | try: |
|
90 | try: | |
91 | with io.open(sheet_filename, encoding='utf-8') as file: |
|
91 | with io.open(sheet_filename, encoding='utf-8') as file: | |
92 | file_text = file.read() |
|
92 | file_text = file.read() | |
93 | header.append(file_text) |
|
93 | header.append(file_text) | |
94 | except IOError: |
|
94 | except IOError: | |
95 |
|
95 | |||
96 | # New version of IPython with style.min.css, pass |
|
96 | # New version of IPython with style.min.css, pass | |
97 | pass |
|
97 | pass | |
98 |
|
98 | |||
99 | #Add pygments CSS |
|
99 | #Add pygments CSS | |
100 | pygments_css = HtmlFormatter().get_style_defs('.highlight') |
|
100 | pygments_css = HtmlFormatter().get_style_defs('.highlight') | |
101 | header.append(pygments_css) |
|
101 | header.append(pygments_css) | |
102 |
|
102 | |||
103 | #Set header |
|
103 | #Set header | |
104 | self.header = header |
|
104 | self.header = header | |
105 |
|
105 |
General Comments 0
You need to be logged in to leave comments.
Login now