##// END OF EJS Templates
fix typo
Matthias BUSSONNIER -
Show More
@@ -1,236 +1,236 b''
1 """
1 """
2
2
3 """
3 """
4
4
5 from __future__ import print_function
5 from __future__ import print_function
6
6
7 from IPython.config.configurable import Configurable
7 from IPython.config.configurable import Configurable
8 from IPython.utils.traitlets import Unicode, Bool, Dict, List
8 from IPython.utils.traitlets import Unicode, Bool, Dict, List
9
9
10 class ConfigurableTransformers(Configurable):
10 class ConfigurableTransformers(Configurable):
11 """ A configurable transformer """
11 """ A configurable transformer """
12
12
13 def __init__(self, config=None, **kw):
13 def __init__(self, config=None, **kw):
14 super(ConfigurableTransformers, self).__init__(config=config, **kw)
14 super(ConfigurableTransformers, self).__init__(config=config, **kw)
15
15
16 def __call__(self, nb, other):
16 def __call__(self, nb, other):
17 try :
17 try :
18 for worksheet in nb.worksheets :
18 for worksheet in nb.worksheets :
19 for index, cell in enumerate(worksheet.cells):
19 for index, cell in enumerate(worksheet.cells):
20 worksheet.cells[index], other = self.cell_transform(cell, other, index)
20 worksheet.cells[index], other = self.cell_transform(cell, other, index)
21 return nb, other
21 return nb, other
22 except NotImplementedError as error :
22 except NotImplementedError as error :
23 raise NotImplementedError('should be implemented by subclass')
23 raise NotImplementedError('should be implemented by subclass')
24
24
25 def cell_transform(self, cell, other, index):
25 def cell_transform(self, cell, other, index):
26 """
26 """
27 Overwrite if you want to apply a transformation on each cell
27 Overwrite if you want to apply a transformation on each cell
28 """
28 """
29 raise NotImplementedError('should be implemented by subclass')
29 raise NotImplementedError('should be implemented by subclass')
30
30
31
31
32 class Foobar(ConfigurableTransformers):
32 class Foobar(ConfigurableTransformers):
33 message = Unicode('-- nothing', config=True)
33 message = Unicode('-- nothing', config=True)
34
34
35
35
36 def cell_transform(self, cell, other, index):
36 def cell_transform(self, cell, other, index):
37 return cell, other
37 return cell, other
38
38
39
39
40 def cell_preprocessor(function):
40 def cell_preprocessor(function):
41 """ wrap a function to be executed on all cells of a notebook
41 """ wrap a function to be executed on all cells of a notebook
42
42
43 wrapped function parameters :
43 wrapped function parameters :
44 cell : the cell
44 cell : the cell
45 other : external resources
45 other : external resources
46 index : index of the cell
46 index : index of the cell
47 """
47 """
48 def wrappedfunc(nb, other):
48 def wrappedfunc(nb, other):
49 for worksheet in nb.worksheets :
49 for worksheet in nb.worksheets :
50 for index, cell in enumerate(worksheet.cells):
50 for index, cell in enumerate(worksheet.cells):
51 worksheet.cells[index], other = function(cell, other, index)
51 worksheet.cells[index], other = function(cell, other, index)
52 return nb, other
52 return nb, other
53 return wrappedfunc
53 return wrappedfunc
54
54
55
55
56 @cell_preprocessor
56 @cell_preprocessor
57 def haspyout_transformer(cell, other, count):
57 def haspyout_transformer(cell, other, count):
58 """
58 """
59 Add a haspyout flag to cell that have it
59 Add a haspyout flag to cell that have it
60
60
61 Easier for templating, where you can't know in advance
61 Easier for templating, where you can't know in advance
62 wether to write the out prompt
62 wether to write the out prompt
63
63
64 """
64 """
65 cell.type = cell.cell_type
65 cell.type = cell.cell_type
66 cell.haspyout = False
66 cell.haspyout = False
67 for out in cell.get('outputs', []):
67 for out in cell.get('outputs', []):
68 if out.output_type == 'pyout':
68 if out.output_type == 'pyout':
69 cell.haspyout = True
69 cell.haspyout = True
70 break
70 break
71 return cell, other
71 return cell, other
72
72
73
73
74 # todo, make the key part configurable.
74 # todo, make the key part configurable.
75
75
76 class ExtractFigureTransformer(ConfigurableTransformers):
76 class ExtractFigureTransformer(ConfigurableTransformers):
77 enabled = Bool(False,
77 enabled = Bool(False,
78 config=True,
78 config=True,
79 help=""" If set to false, this transformer will be no-op """
79 help=""" If set to false, this transformer will be no-op """
80 )
80 )
81
81
82 extra_ext_map = Dict({},
82 extra_ext_map = Dict({},
83 config=True,
83 config=True,
84 help="""extra map to override extension based on type.
84 help="""extra map to override extension based on type.
85 Usefull for latex where svg will be converted to pdf before inclusion
85 Usefull for latex where svg will be converted to pdf before inclusion
86 """
86 """
87 )
87 )
88 display_data_priority = List(['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'],
88 display_data_priority = List(['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'],
89 config=True,
89 config=True,
90 help= """
90 help= """
91 An ordered list of prefered output type, the first
91 An ordered list of prefered output type, the first
92 encounterd will usually be used when converting discarding
92 encounterd will usually be used when converting discarding
93 the others.
93 the others.
94 """
94 """
95 )
95 )
96
96
97
97
98 #to do change this to .format {} syntax
98 #to do change this to .format {} syntax
99 key_tpl = Unicode('_fig_%02i.%s', config=True)
99 key_tpl = Unicode('_fig_%02i.%s', config=True)
100
100
101 def _get_ext(self, ext):
101 def _get_ext(self, ext):
102 if ext in self.extra_ext_map :
102 if ext in self.extra_ext_map :
103 return self.extra_ext_map[ext]
103 return self.extra_ext_map[ext]
104 return ext
104 return ext
105
105
106 def _new_figure(self, data, fmt, count):
106 def _new_figure(self, data, fmt, count):
107 """Create a new figure file in the given format.
107 """Create a new figure file in the given format.
108
108
109 Returns a path relative to the input file.
109 Returns a path relative to the input file.
110 """
110 """
111 figname = self.key_tpl % (count, self._get_ext(fmt))
111 figname = self.key_tpl % (count, self._get_ext(fmt))
112 key = self.key_tpl % (count, fmt)
112 key = self.key_tpl % (count, fmt)
113
113
114 # Binary files are base64-encoded, SVG is already XML
114 # Binary files are base64-encoded, SVG is already XML
115 if fmt in ('png', 'jpg', 'pdf'):
115 if fmt in ('png', 'jpg', 'pdf'):
116 data = data.decode('base64')
116 data = data.decode('base64')
117
117
118 return figname, key, data
118 return figname, key, data
119
119
120
120
121 def cell_transform(self, cell, other, count):
121 def cell_transform(self, cell, other, count):
122 if not self.enabled:
122 if not self.enabled:
123 return cell, other
123 return cell, other
124 if other.get('figures',None) is None :
124 if other.get('figures',None) is None :
125 other['figures']={}
125 other['figures']={}
126 for i, out in enumerate(cell.get('outputs', [])):
126 for i, out in enumerate(cell.get('outputs', [])):
127 for type in self.display_data_priority:
127 for type in self.display_data_priority:
128 if out.hasattr(type):
128 if out.hasattr(type):
129 figname, key, data = self._new_figure(out[type], type, count)
129 figname, key, data = self._new_figure(out[type], type, count)
130 out['key_'+type] = figname
130 out['key_'+type] = figname
131 other['figures'][key] = data
131 other['figures'][key] = data
132 count = count+1
132 count = count+1
133 return cell, other
133 return cell, other
134
134
135 class RevealHelpTransformer(ConfigurableTransformers):
135 class RevealHelpTransformer(ConfigurableTransformers):
136
136
137 section_open = False
137 section_open = False
138 subsection_open = False
138 subsection_open = False
139 fragment_open = False
139 fragment_open = False
140
140
141 def open_subsection(self):
141 def open_subsection(self):
142 self.subsection_open = True
142 self.subsection_open = True
143 return True
143 return True
144
144
145 def open_section(self):
145 def open_section(self):
146 self.section_open = True
146 self.section_open = True
147 return True
147 return True
148
148
149 def open_fragment(self):
149 def open_fragment(self):
150 self.fragment_open = True
150 self.fragment_open = True
151 return True
151 return True
152
152
153 # could probaly write those maybe_close/open
153 # could probaly write those maybe_close/open
154 # with a function functor
154 # with a function functor
155 def maybe_close_section(self):
155 def maybe_close_section(self):
156 """return True is already open, false otherwise
156 """return True is already open, false otherwise
157 and change state to close
157 and change state to close
158 """
158 """
159 if self.section_open :
159 if self.section_open :
160 self.section_open = False
160 self.section_open = False
161 return True
161 return True
162 else :
162 else :
163 return False
163 return False
164
164
165 def maybe_open_section(self):
165 def maybe_open_section(self):
166 """return True is already open, false otherwise
166 """return True is already open, false otherwise
167 and change state to close
167 and change state to close
168 """
168 """
169 if not self.section_open :
169 if not self.section_open :
170 self.section_open = True
170 self.section_open = True
171 return True
171 return True
172 else :
172 else :
173 return False
173 return False
174
174
175 def maybe_open_subsection(self):
175 def maybe_open_subsection(self):
176 """return True is already open, false otherwise
176 """return True is already open, false otherwise
177 and change state to close
177 and change state to close
178 """
178 """
179 if not self.subsection_open :
179 if not self.subsection_open :
180 self.subsection_open = True
180 self.subsection_open = True
181 return True
181 return True
182 else :
182 else :
183 return False
183 return False
184
184
185 def maybe_close_subsection(self):
185 def maybe_close_subsection(self):
186 """return True is already open, false otherwise
186 """return True is already open, false otherwise
187 and change state to close
187 and change state to close
188 """
188 """
189 if self.subsection_open :
189 if self.subsection_open :
190 self.subsection_open = False
190 self.subsection_open = False
191 return True
191 return True
192 else :
192 else :
193 return False
193 return False
194
194
195 def maybe_close_fragment(self):
195 def maybe_close_fragment(self):
196 """return True is already open, false otherwise
196 """return True is already open, false otherwise
197 and change state to close
197 and change state to close
198 """
198 """
199 if self.fragment_open :
199 if self.fragment_open :
200 self.fragment_open = False
200 self.fragment_open = False
201 return True
201 return True
202 else :
202 else :
203 return False
203 return False
204
204
205 def cell_transform(self, cell, other,count):
205 def cell_transform(self, cell, other,count):
206 ctype = cell.metadata.get('slideshow',{}).get('slide_type',None)
206 ctype = cell.metadata.get('slideshow',{}).get('slide_type',None)
207 if ctype is None :
207 if ctype in [None, '-'] :
208 cell.metadata.slideshow = {}
208 cell.metadata.slideshow = {}
209 cell.metadata.slideshow['slide_type'] = None
209 cell.metadata.slideshow['slide_type'] = None
210 elif ctype == 'fragment':
210 elif ctype == 'fragment':
211 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
211 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
212 cell.metadata.slideshow.close_subsection = False
212 cell.metadata.slideshow.close_subsection = False
213 cell.metadata.slideshow.close_section = False
213 cell.metadata.slideshow.close_section = False
214
214
215 cell.metadata.slideshow.open_section = self.maybe_open_section()
215 cell.metadata.slideshow.open_section = self.maybe_open_section()
216 cell.metadata.slideshow.open_subsection = self.maybe_open_subsection()
216 cell.metadata.slideshow.open_subsection = self.maybe_open_subsection()
217 cell.metadata.slideshow.open_fragment = self.open_fragment()
217 cell.metadata.slideshow.open_fragment = self.open_fragment()
218
218
219 elif ctype == 'subslide':
219 elif ctype == 'subslide':
220 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
220 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
221 cell.metadata.slideshow.close_subsection = self.maybe_close_subsection()
221 cell.metadata.slideshow.close_subsection = self.maybe_close_subsection()
222 cell.metadata.slideshow.close_section = False
222 cell.metadata.slideshow.close_section = False
223
223
224 cell.metadata.slideshow.open_section = self.maybe_open_section()
224 cell.metadata.slideshow.open_section = self.maybe_open_section()
225 cell.metadata.slideshow.open_subsection = self.open_subsection()
225 cell.metadata.slideshow.open_subsection = self.open_subsection()
226 cell.metadata.slideshow.open_fragment = False
226 cell.metadata.slideshow.open_fragment = False
227 elif ctype == 'slide':
227 elif ctype == 'slide':
228 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
228 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
229 cell.metadata.slideshow.close_subsection = self.maybe_close_subsection()
229 cell.metadata.slideshow.close_subsection = self.maybe_close_subsection()
230 cell.metadata.slideshow.close_section = self.maybe_close_section()
230 cell.metadata.slideshow.close_section = self.maybe_close_section()
231
231
232 cell.metadata.slideshow.open_section = self.open_section()
232 cell.metadata.slideshow.open_section = self.open_section()
233 cell.metadata.slideshow.open_subsection = self.open_subsection()
233 cell.metadata.slideshow.open_subsection = self.open_subsection()
234 cell.metadata.slideshow.open_fragment = False
234 cell.metadata.slideshow.open_fragment = False
235 return cell,other
235 return cell,other
236
236
@@ -1,150 +1,150 b''
1 {%- extends 'basichtml.tpl' -%}
1 {%- extends 'basichtml.tpl' -%}
2
2
3
3
4 {% block any_cell -%}
4 {% block any_cell -%}
5
5
6 {% if cell.metadata.slideshow.close_fragment %}
6 {% if cell.metadata.slideshow.close_fragment %}
7 </div>
7 </div>
8 {% endif %}
8 {% endif %}
9 {% if cell.metadata.slideshow.close_subsection %}
9 {% if cell.metadata.slideshow.close_subsection %}
10 </section>
10 </section>
11 {% endif %}
11 {% endif %}
12 {% if cell.metadata.slideshow.close_section %}
12 {% if cell.metadata.slideshow.close_section %}
13 </section>
13 </section>
14 {% endif %}
14 {% endif %}
15
15
16 {% if cell.metadata.slideshow.open_section %}
16 {% if cell.metadata.slideshow.open_section %}
17 <section>
17 <section>
18 {%- endif %}
18 {%- endif %}
19 {% if cell.metadata.slideshow.open_subsection %}
19 {% if cell.metadata.slideshow.open_subsection %}
20 <section>
20 <section>
21 {%- endif %}
21 {%- endif %}
22 {% if cell.metadata.slideshow.open_fragment %}
22 {% if cell.metadata.slideshow.open_fragment %}
23 <div class='fragment'>
23 <div class='fragment'>
24 {% endif %}
24 {% endif %}
25 {% if cell.metadata.slideshow.slide_type in ['notes'] %}
25 {% if cell.metadata.slideshow.slide_type in ['notes'] %}
26 <aside class="notes">
26 <aside class="notes">
27 {{ super() }}
27 {{ super() }}
28 </aside>
28 </aside>
29 {% elif cell.metadata.slideshow.slide_tyle not in ['skip'] %}
29 {% elif cell.metadata.slideshow.slide_type not in ['skip'] %}
30 {{ super() }}
30 {{ super() }}
31 {% endif %}
31 {% endif %}
32
32
33 {% endblock %}
33 {% endblock %}
34
34
35
35
36 {% block body %}
36 {% block body %}
37 <body>
37 <body>
38 <div class="reveal"><div class="slides">
38 <div class="reveal"><div class="slides">
39 {{ super() }}
39 {{ super() }}
40 </section>
40 </section>
41 </section>
41 </section>
42 </div></div>
42 </div></div>
43
43
44 <script src="reveal/lib/js/head.min.js"></script>
44 <script src="reveal/lib/js/head.min.js"></script>
45
45
46 <script src="reveal/js/reveal.min.js"></script>
46 <script src="reveal/js/reveal.min.js"></script>
47
47
48 <script>
48 <script>
49
49
50 // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration
50 // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration
51 Reveal.initialize({
51 Reveal.initialize({
52 controls: true,
52 controls: true,
53 progress: true,
53 progress: true,
54 history: true,
54 history: true,
55
55
56 theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
56 theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
57 transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
57 transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
58
58
59 // Optional libraries used to extend on reveal.js
59 // Optional libraries used to extend on reveal.js
60 dependencies: [
60 dependencies: [
61 { src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } },
61 { src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } },
62 { src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
62 { src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
63 { src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
63 { src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
64 { src: 'notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
64 { src: 'notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
65 { src: 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', async: true },
65 { src: 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', async: true },
66 { src: 'js/revealmathjax.js', async: true}
66 { src: 'js/revealmathjax.js', async: true}
67 ]
67 ]
68 });
68 });
69 </script>
69 </script>
70
70
71 <script>
71 <script>
72 Reveal.addEventListener( 'slidechanged', function( event ) {
72 Reveal.addEventListener( 'slidechanged', function( event ) {
73 MathJax.Hub.Rerender(event.currentSlide);
73 MathJax.Hub.Rerender(event.currentSlide);
74 });
74 });
75 </script>
75 </script>
76 </body>
76 </body>
77 </html>{% endblock body %}
77 </html>{% endblock body %}
78
78
79
79
80
80
81
81
82 {% block header %}<!DOCTYPE html>
82 {% block header %}<!DOCTYPE html>
83 <html>
83 <html>
84 <head>
84 <head>
85
85
86 <meta charset="utf-8" />
86 <meta charset="utf-8" />
87 <meta http-equiv="X-UA-Compatible" content="chrome=1">
87 <meta http-equiv="X-UA-Compatible" content="chrome=1">
88
88
89 <meta name="apple-mobile-web-app-capable" content="yes" />
89 <meta name="apple-mobile-web-app-capable" content="yes" />
90 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
90 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
91
91
92 <link rel="stylesheet" href="reveal/css/reveal.css">
92 <link rel="stylesheet" href="reveal/css/reveal.css">
93 <link rel="stylesheet" href="reveal/css/theme/simple.css" id="theme">
93 <link rel="stylesheet" href="reveal/css/theme/simple.css" id="theme">
94
94
95 <!-- For syntax highlighting -->
95 <!-- For syntax highlighting -->
96 <link rel="stylesheet" href="reveal/lib/css/zenburn.css">
96 <link rel="stylesheet" href="reveal/lib/css/zenburn.css">
97
97
98 <!-- If the query includes 'print-pdf', use the PDF print sheet -->
98 <!-- If the query includes 'print-pdf', use the PDF print sheet -->
99 <script>
99 <script>
100 document.write( '<link rel="stylesheet" href="reveal/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
100 document.write( '<link rel="stylesheet" href="reveal/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
101 </script>
101 </script>
102
102
103 <!--[if lt IE 9]>
103 <!--[if lt IE 9]>
104 <script src="reveal/lib/js/html5shiv.js"></script>
104 <script src="reveal/lib/js/html5shiv.js"></script>
105 <![endif]-->
105 <![endif]-->
106
106
107 {% for css in inlining.css -%}
107 {% for css in inlining.css -%}
108 <style type="text/css">
108 <style type="text/css">
109 {{css}}
109 {{css}}
110 </style>
110 </style>
111 {% endfor %}
111 {% endfor %}
112
112
113 <style type="text/css">
113 <style type="text/css">
114 /* Overrides of notebook CSS for static HTML export */
114 /* Overrides of notebook CSS for static HTML export */
115
115
116 .reveal {
116 .reveal {
117 font-size: 20px;
117 font-size: 20px;
118 }
118 }
119 .reveal pre {
119 .reveal pre {
120 width: 100%;
120 width: 100%;
121 padding: 0.2em;
121 padding: 0.2em;
122 margin: 0px auto;
122 margin: 0px auto;
123 font-family: monospace, sans-serif;
123 font-family: monospace, sans-serif;
124 font-size: 60%;
124 font-size: 60%;
125 box-shadow: 0px 0px 0px rgba(0, 0, 0, 0);
125 box-shadow: 0px 0px 0px rgba(0, 0, 0, 0);
126 }
126 }
127 .reveal section img {
127 .reveal section img {
128 border: 0px solid black;
128 border: 0px solid black;
129 box-shadow: 0 0 10px rgba(0, 0, 0, 0);
129 box-shadow: 0 0 10px rgba(0, 0, 0, 0);
130 }
130 }
131 div.input_area {
131 div.input_area {
132 padding: 0.2em;
132 padding: 0.2em;
133 }
133 }
134 div.code_cell {
134 div.code_cell {
135 background-color: transparent;
135 background-color: transparent;
136 }
136 }
137 div.prompt {
137 div.prompt {
138 width: 11ex;
138 width: 11ex;
139 padding: 0.0em;
139 padding: 0.0em;
140 margin: 0px;
140 margin: 0px;
141 font-family: monospace;
141 font-family: monospace;
142 font-size: 60%;
142 font-size: 60%;
143 text-align: center;
143 text-align: center;
144 }
144 }
145 div.output_prompt {
145 div.output_prompt {
146 /* 5px right shift to account for margin in parent container */
146 /* 5px right shift to account for margin in parent container */
147 margin: 5px 5px 0 -5px;
147 margin: 5px 5px 0 -5px;
148 }
148 }
149 </style>
149 </style>
150 </head>{% endblock %}
150 </head>{% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now