##// END OF EJS Templates
Merge pull request #3533 from damianavila/reveal_cdn...
Min RK -
r11196:719de27e merge
parent child Browse files
Show More
@@ -1,54 +1,61
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 BasicHTMLExporter
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(BasicHTMLExporter):
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({'CSSHTMLHeaderTransformer':{'enabled':True}})
52 c = Config({
53 'CSSHTMLHeaderTransformer':{
54 'enabled':True
55 },
56 'RevealHelpTransformer':{
57 'enabled':True,
58 },
59 })
53 c.merge(super(RevealExporter,self).default_config)
60 c.merge(super(RevealExporter,self).default_config)
54 return c
61 return c
@@ -1,180 +1,181
1 {%- extends 'slides.tpl' -%}
1 {%- extends 'slides.tpl' -%}
2
2
3
3
4 {% block header %}
4 {% block header %}
5 <!DOCTYPE html>
5 <!DOCTYPE html>
6 <html>
6 <html>
7 <head>
7 <head>
8
8
9 <meta charset="utf-8" />
9 <meta charset="utf-8" />
10 <meta http-equiv="X-UA-Compatible" content="chrome=1">
10 <meta http-equiv="X-UA-Compatible" content="chrome=1">
11
11
12 <meta name="apple-mobile-web-app-capable" content="yes" />
12 <meta name="apple-mobile-web-app-capable" content="yes" />
13 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
13 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
14
14
15 <link rel="stylesheet" href="reveal.js/css/reveal.css">
15 <!-- General and theme style sheets -->
16 <link rel="stylesheet" href="reveal.js/css/theme/simple.css" id="theme">
16 <link rel="stylesheet" href="{{resources.reveal.url_prefix}}/css/reveal.css">
17 <link rel="stylesheet" href="{{resources.reveal.url_prefix}}/css/theme/simple.css" id="theme">
17
18
18 <!-- For syntax highlighting -->
19 <!-- For syntax highlighting -->
19 <link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
20 <link rel="stylesheet" href="{{resources.reveal.url_prefix}}/lib/css/zenburn.css">
20
21
21 <!-- If the query includes 'print-pdf', use the PDF print sheet -->
22 <!-- If the query includes 'print-pdf', use the PDF print sheet -->
22 <script>
23 <script>
23 document.write( '<link rel="stylesheet" href="reveal.js/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
24 document.write( '<link rel="stylesheet" href="{{resources.reveal.url_prefix}}/css/print' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
24 </script>
25 </script>
25
26
26 <!--[if lt IE 9]>
27 <!--[if lt IE 9]>
27 <script src="reveal.js/lib/js/html5shiv.js"></script>
28 <script src="{{resources.reveal.url_prefix}}/lib/js/html5shiv.js"></script>
28 <![endif]-->
29 <![endif]-->
29
30
30 {% for css in resources.inlining.css -%}
31 {% for css in resources.inlining.css -%}
31 <style type="text/css">
32 <style type="text/css">
32 {{css}}
33 {{css}}
33 </style>
34 </style>
34 {% endfor %}
35 {% endfor %}
35
36
36 <style type="text/css">
37 <style type="text/css">
37 /* Overrides of notebook CSS for static HTML export */
38 /* Overrides of notebook CSS for static HTML export */
38 .reveal {
39 .reveal {
39 font-size: 20px;
40 font-size: 20px;
40 overflow-y: auto;
41 overflow-y: auto;
41 overflow-x: hidden;
42 overflow-x: hidden;
42 }
43 }
43 .reveal pre {
44 .reveal pre {
44 width: 95%;
45 width: 95%;
45 padding: 0.4em;
46 padding: 0.4em;
46 margin: 0px;
47 margin: 0px;
47 font-family: monospace, sans-serif;
48 font-family: monospace, sans-serif;
48 font-size: 80%;
49 font-size: 80%;
49 box-shadow: 0px 0px 0px rgba(0, 0, 0, 0);
50 box-shadow: 0px 0px 0px rgba(0, 0, 0, 0);
50 }
51 }
51 .reveal section img {
52 .reveal section img {
52 border: 0px solid black;
53 border: 0px solid black;
53 box-shadow: 0 0 10px rgba(0, 0, 0, 0);
54 box-shadow: 0 0 10px rgba(0, 0, 0, 0);
54 }
55 }
55 .reveal .slides {
56 .reveal .slides {
56 text-align: left;
57 text-align: left;
57 }
58 }
58 .reveal.fade {
59 .reveal.fade {
59 opacity: 1;
60 opacity: 1;
60 }
61 }
61 div.input_area {
62 div.input_area {
62 padding: 0.06em;
63 padding: 0.06em;
63 }
64 }
64 div.code_cell {
65 div.code_cell {
65 background-color: transparent;
66 background-color: transparent;
66 }
67 }
67 div.prompt {
68 div.prompt {
68 width: 11ex;
69 width: 11ex;
69 padding: 0.4em;
70 padding: 0.4em;
70 margin: 0px;
71 margin: 0px;
71 font-family: monospace, sans-serif;
72 font-family: monospace, sans-serif;
72 font-size: 80%;
73 font-size: 80%;
73 text-align: right;
74 text-align: right;
74 }
75 }
75 div.output_area pre {
76 div.output_area pre {
76 font-family: monospace, sans-serif;
77 font-family: monospace, sans-serif;
77 font-size: 80%;
78 font-size: 80%;
78 }
79 }
79 div.output_prompt {
80 div.output_prompt {
80 /* 5px right shift to account for margin in parent container */
81 /* 5px right shift to account for margin in parent container */
81 margin: 5px 5px 0 -5px;
82 margin: 5px 5px 0 -5px;
82 }
83 }
83 .rendered_html p {
84 .rendered_html p {
84 text-align: inherit;
85 text-align: inherit;
85 }
86 }
86 </style>
87 </style>
87 </head>
88 </head>
88 {% endblock header%}
89 {% endblock header%}
89
90
90
91
91 {% block body %}
92 {% block body %}
92 <body>
93 <body>
93 <div class="reveal"><div class="slides">
94 <div class="reveal"><div class="slides">
94
95
95 {{ super() }}
96 {{ super() }}
96
97
97 </div></div>
98 </div></div>
98
99
99 <!--
100 <!--
100 Uncomment the following block and the addthis_widget.js (see below inside dependencies)
101 Uncomment the following block and the addthis_widget.js (see below inside dependencies)
101 to get enable social buttons.
102 to get enable social buttons.
102 -->
103 -->
103
104
104 <!--
105 <!--
105 <div class="addthis_toolbox addthis_floating_style addthis_32x32_style" style="left:20px;top:20px;">
106 <div class="addthis_toolbox addthis_floating_style addthis_32x32_style" style="left:20px;top:20px;">
106 <a class="addthis_button_twitter"></a>
107 <a class="addthis_button_twitter"></a>
107 <a class="addthis_button_google_plusone_share"></a>
108 <a class="addthis_button_google_plusone_share"></a>
108 <a class="addthis_button_linkedin"></a>
109 <a class="addthis_button_linkedin"></a>
109 <a class="addthis_button_facebook"></a>
110 <a class="addthis_button_facebook"></a>
110 <a class="addthis_button_more"></a>
111 <a class="addthis_button_more"></a>
111 </div>
112 </div>
112 -->
113 -->
113
114
114 <script src="reveal.js/lib/js/head.min.js"></script>
115 <script src="{{resources.reveal.url_prefix}}/lib/js/head.min.js"></script>
115
116
116 <script src="reveal.js/js/reveal.min.js"></script>
117 <script src="{{resources.reveal.url_prefix}}/js/reveal.js"></script>
117
118
118 <script>
119 <script>
119
120
120 // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration
121 // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration
121 Reveal.initialize({
122 Reveal.initialize({
122 controls: true,
123 controls: true,
123 progress: true,
124 progress: true,
124 history: true,
125 history: true,
125
126
126 theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
127 theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
127 transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
128 transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
128
129
129 // Optional libraries used to extend on reveal.js
130 // Optional libraries used to extend on reveal.js
130 dependencies: [
131 dependencies: [
131 { src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
132 { src: "{{resources.reveal.url_prefix}}/lib/js/classList.js", condition: function() { return !document.body.classList; } },
132 { src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
133 { src: "{{resources.reveal.url_prefix}}/plugin/highlight/highlight.js", async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
133 { src: 'reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
134 { src: "{{resources.reveal.url_prefix}}/plugin/notes/notes.js", async: true, condition: function() { return !!document.body.classList; } }
134 // { src: 'http://s7.addthis.com/js/300/addthis_widget.js', async: true},
135 // { src: 'http://s7.addthis.com/js/300/addthis_widget.js', async: true},
135 ]
136 ]
136 });
137 });
137 </script>
138 </script>
138
139
139 <!-- MathJax configuration -->
140 <!-- MathJax configuration -->
140 <script type="text/x-mathjax-config">
141 <script type="text/x-mathjax-config">
141 MathJax.Hub.Config({
142 MathJax.Hub.Config({
142 tex2jax: {
143 tex2jax: {
143 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
144 inlineMath: [ ['$','$'], ["\\(","\\)"] ],
144 displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
145 displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
145 },
146 },
146 displayAlign: 'left', // Change this to 'center' to center equations.
147 displayAlign: 'left', // Change this to 'center' to center equations.
147 "HTML-CSS": {
148 "HTML-CSS": {
148 styles: {'.MathJax_Display': {"margin": 0}}
149 styles: {'.MathJax_Display': {"margin": 0}}
149 }
150 }
150 });
151 });
151 </script>
152 </script>
152 <!-- End of mathjax configuration -->
153 <!-- End of mathjax configuration -->
153
154
154 <script>
155 <script>
155 // We wait for the onload function to load MathJax after the page is completely loaded.
156 // We wait for the onload function to load MathJax after the page is completely loaded.
156 // MathJax is loaded 1 unit of time after the page is ready.
157 // MathJax is loaded 1 unit of time after the page is ready.
157 // This hack prevent problems when you load multiple js files (i.e. social button from addthis).
158 // This hack prevent problems when you load multiple js files (i.e. social button from addthis).
158 //
159 //
159 window.onload = function () {
160 window.onload = function () {
160 setTimeout(function () {
161 setTimeout(function () {
161 var script = document.createElement("script");
162 var script = document.createElement("script");
162 script.type = "text/javascript";
163 script.type = "text/javascript";
163 script.src = "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML";
164 script.src = "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML";
164 document.getElementsByTagName("head")[0].appendChild(script);
165 document.getElementsByTagName("head")[0].appendChild(script);
165 },1)
166 },1)
166 }
167 }
167 </script>
168 </script>
168
169
169 <script>
170 <script>
170 Reveal.addEventListener( 'slidechanged', function( event ) {
171 Reveal.addEventListener( 'slidechanged', function( event ) {
171 MathJax.Hub.Rerender(event.currentSlide);
172 MathJax.Hub.Rerender(event.currentSlide);
172 });
173 });
173 </script>
174 </script>
174
175
175 </body>
176 </body>
176 {% endblock body %}
177 {% endblock body %}
177
178
178 {% block footer %}
179 {% block footer %}
179 </html>
180 </html>
180 {% endblock footer %}
181 {% endblock footer %}
@@ -1,52 +1,62
1 """Module that pre-processes the notebook for export via Reveal.
1 """Module that pre-processes the notebook for export via Reveal.
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 from .base import ConfigurableTransformer
15 from .base import ConfigurableTransformer
16 from IPython.utils.traitlets import Unicode
16
17
17 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
18 # Classes and functions
19 # Classes and functions
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20
21
21 class RevealHelpTransformer(ConfigurableTransformer):
22 class RevealHelpTransformer(ConfigurableTransformer):
22
23
24 url_prefix = Unicode('//cdn.jsdelivr.net/reveal.js/2.4.0',
25 config=True,
26 help="""If you want to use a local reveal.js library,
27 use 'url_prefix':'reveal.js' in your config object.""")
28
23 def call(self, nb, resources):
29 def call(self, nb, resources):
24 """
30 """
25 Called once to 'transform' contents of the notebook.
31 Called once to 'transform' contents of the notebook.
26
32
27 Parameters
33 Parameters
28 ----------
34 ----------
29 nb : NotebookNode
35 nb : NotebookNode
30 Notebook being converted
36 Notebook being converted
31 resources : dictionary
37 resources : dictionary
32 Additional resources used in the conversion process. Allows
38 Additional resources used in the conversion process. Allows
33 transformers to pass variables into the Jinja engine.
39 transformers to pass variables into the Jinja engine.
34 """
40 """
35
41
36
42
37 for worksheet in nb.worksheets :
43 for worksheet in nb.worksheets :
38 for i, cell in enumerate(worksheet.cells):
44 for i, cell in enumerate(worksheet.cells):
39
45
40 #Make sure the cell has slideshow metadata.
46 #Make sure the cell has slideshow metadata.
41 cell.metadata.align_type = cell.get('metadata', {}).get('slideshow', {}).get('align_type', 'Left')
47 cell.metadata.align_type = cell.get('metadata', {}).get('slideshow', {}).get('align_type', 'Left')
42 cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
48 cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
43
49
44 #Get the slide type. If type is start of subslide or slide,
50 #Get the slide type. If type is start of subslide or slide,
45 #end the last subslide/slide.
51 #end the last subslide/slide.
46 if cell.metadata.slide_type in ['slide']:
52 if cell.metadata.slide_type in ['slide']:
47 worksheet.cells[i - 1].metadata.slide_helper = 'slide_end'
53 worksheet.cells[i - 1].metadata.slide_helper = 'slide_end'
48 if cell.metadata.slide_type in ['subslide']:
54 if cell.metadata.slide_type in ['subslide']:
49 worksheet.cells[i - 1].metadata.slide_helper = 'subslide_end'
55 worksheet.cells[i - 1].metadata.slide_helper = 'subslide_end'
50
56
57
58 if 'reveal' not in resources:
59 resources['reveal'] = {}
60 resources['reveal']['url_prefix'] = self.url_prefix
61
51 return nb, resources
62 return nb, resources
52 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now