Show More
@@ -1,137 +1,134 | |||||
1 | from converters.markdown import ConverterMarkdown |
|
1 | from converters.markdown import ConverterMarkdown | |
2 | import io |
|
2 | import io | |
3 | import os |
|
3 | import os | |
4 |
|
4 | |||
5 | class ConverterSlider(ConverterMarkdown): |
|
5 | class ConverterSlider(ConverterMarkdown): | |
6 |
"""Convert a notebook to html suitable for |
|
6 | """Convert a notebook to a html slideshow suitable for oral presentations. | |
7 |
|
7 | |||
8 | It generates an html file that has *only* the pure HTML contents, and a |
|
8 | It generates a static html slideshow based in markdown and reveal.js. | |
9 | separate file with `_header` appended to the name with all header contents. |
|
|||
10 | Typically, the header file only needs to be used once when setting up a |
|
|||
11 | blog, as the CSS for all posts is stored in a single location in Blogger. |
|
|||
12 | """ |
|
9 | """ | |
13 |
|
10 | |||
14 | def __init__(self, infile, highlight_source=False, show_prompts=True, |
|
11 | def __init__(self, infile, highlight_source=False, show_prompts=True, | |
15 | inline_prompt=True): |
|
12 | inline_prompt=True): | |
16 | super(ConverterMarkdown, self).__init__(infile) |
|
13 | super(ConverterMarkdown, self).__init__(infile) | |
17 | self.highlight_source = highlight_source |
|
14 | self.highlight_source = highlight_source | |
18 | self.show_prompts = show_prompts |
|
15 | self.show_prompts = show_prompts | |
19 | self.inline_prompt = inline_prompt |
|
16 | self.inline_prompt = inline_prompt | |
20 |
|
17 | |||
21 | def convert(self, cell_separator='\n'): |
|
18 | def convert(self, cell_separator='\n'): | |
22 | """ |
|
19 | """ | |
23 | Generic method to converts notebook to a string representation. |
|
20 | Generic method to converts notebook to a string representation. | |
24 |
|
21 | |||
25 | This is accomplished by dispatching on the cell_type, so subclasses of |
|
22 | This is accomplished by dispatching on the cell_type, so subclasses of | |
26 | Convereter class do not need to re-implement this method, but just |
|
23 | Convereter class do not need to re-implement this method, but just | |
27 | need implementation for the methods that will be dispatched. |
|
24 | need implementation for the methods that will be dispatched. | |
28 |
|
25 | |||
29 | Parameters |
|
26 | Parameters | |
30 | ---------- |
|
27 | ---------- | |
31 | cell_separator : string |
|
28 | cell_separator : string | |
32 | Character or string to join cells with. Default is "\n" |
|
29 | Character or string to join cells with. Default is "\n" | |
33 |
|
30 | |||
34 | Returns |
|
31 | Returns | |
35 | ------- |
|
32 | ------- | |
36 | out : string |
|
33 | out : string | |
37 | """ |
|
34 | """ | |
38 | lines = [] |
|
35 | lines = [] | |
39 | lines.extend(self.optional_header()) |
|
36 | lines.extend(self.optional_header()) | |
40 | top = '<section data-markdown><script type="text/template">' |
|
37 | top = '<section data-markdown><script type="text/template">' | |
41 | bottom = '</script></section>' |
|
38 | bottom = '</script></section>' | |
42 | text = self.main_body(cell_separator) |
|
39 | text = self.main_body(cell_separator) | |
43 | for i,j in enumerate(text): |
|
40 | for i,j in enumerate(text): | |
44 | if j == u'---': |
|
41 | if j == u'---': | |
45 | text[i] = bottom + top |
|
42 | text[i] = bottom + top | |
46 | lines.extend(text) |
|
43 | lines.extend(text) | |
47 | lines.extend(self.optional_footer()) |
|
44 | lines.extend(self.optional_footer()) | |
48 | return u'\n'.join(lines) |
|
45 | return u'\n'.join(lines) | |
49 |
|
46 | |||
50 | def save(self, outfile=None, encoding=None): |
|
47 | def save(self, outfile=None, encoding=None): | |
51 | "read and parse notebook into self.nb" |
|
48 | "read and parse notebook into self.nb" | |
52 | if outfile is None: |
|
49 | if outfile is None: | |
53 | outfile = self.outbase + '_slides.' + 'html' |
|
50 | outfile = self.outbase + '_slides.' + 'html' | |
54 | if encoding is None: |
|
51 | if encoding is None: | |
55 | encoding = self.default_encoding |
|
52 | encoding = self.default_encoding | |
56 | with io.open(outfile, 'w', encoding=encoding) as f: |
|
53 | with io.open(outfile, 'w', encoding=encoding) as f: | |
57 | f.write(self.output) |
|
54 | f.write(self.output) | |
58 | return os.path.abspath(outfile) |
|
55 | return os.path.abspath(outfile) | |
59 |
|
56 | |||
60 | def optional_header(self): |
|
57 | def optional_header(self): | |
61 | optional_header_body = [\ |
|
58 | optional_header_body = [\ | |
62 | ''' |
|
59 | ''' | |
63 | <!DOCTYPE html> |
|
60 | <!DOCTYPE html> | |
64 | <html> |
|
61 | <html> | |
65 | <head> |
|
62 | <head> | |
66 | <meta charset="utf-8" /> |
|
63 | <meta charset="utf-8" /> | |
67 | <meta http-equiv="X-UA-Compatible" content="chrome=1"> |
|
64 | <meta http-equiv="X-UA-Compatible" content="chrome=1"> | |
68 |
|
65 | |||
69 | <meta name="apple-mobile-web-app-capable" content="yes" /> |
|
66 | <meta name="apple-mobile-web-app-capable" content="yes" /> | |
70 | <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> |
|
67 | <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> | |
71 |
|
68 | |||
72 | <link rel="stylesheet" href="reveal/css/reveal.css"> |
|
69 | <link rel="stylesheet" href="reveal/css/reveal.css"> | |
73 | <link rel="stylesheet" href="reveal/css/theme/default.css" id="theme"> |
|
70 | <link rel="stylesheet" href="reveal/css/theme/default.css" id="theme"> | |
74 |
|
71 | |||
75 | <!-- For syntax highlighting --> |
|
72 | <!-- For syntax highlighting --> | |
76 | <link rel="stylesheet" href="reveal/lib/css/zenburn.css"> |
|
73 | <link rel="stylesheet" href="reveal/lib/css/zenburn.css"> | |
77 |
|
74 | |||
78 | <!-- If the query includes 'print-pdf', use the PDF print sheet --> |
|
75 | <!-- If the query includes 'print-pdf', use the PDF print sheet --> | |
79 | <script> |
|
76 | <script> | |
80 | document.write( '<link rel="stylesheet" href="reveal/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' ); |
|
77 | document.write( '<link rel="stylesheet" href="reveal/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' ); | |
81 | </script> |
|
78 | </script> | |
82 |
|
79 | |||
83 | <!--[if lt IE 9]> |
|
80 | <!--[if lt IE 9]> | |
84 | <script src="reveal/lib/js/html5shiv.js"></script> |
|
81 | <script src="reveal/lib/js/html5shiv.js"></script> | |
85 | <![endif]--> |
|
82 | <![endif]--> | |
86 |
|
83 | |||
87 | </head> |
|
84 | </head> | |
88 | <body><div class="reveal"><div class="slides"> |
|
85 | <body><div class="reveal"><div class="slides"> | |
89 | <section data-markdown><script type="text/template"> |
|
86 | <section data-markdown><script type="text/template"> | |
90 | '''] |
|
87 | '''] | |
91 | return optional_header_body |
|
88 | return optional_header_body | |
92 |
|
89 | |||
93 | def optional_footer(self): |
|
90 | def optional_footer(self): | |
94 | optional_footer_body = [\ |
|
91 | optional_footer_body = [\ | |
95 | ''' |
|
92 | ''' | |
96 | </script></section> |
|
93 | </script></section> | |
97 | </div></div> |
|
94 | </div></div> | |
98 |
|
95 | |||
99 | <script src="reveal/lib/js/head.min.js"></script> |
|
96 | <script src="reveal/lib/js/head.min.js"></script> | |
100 |
|
97 | |||
101 | <script src="reveal/js/reveal.min.js"></script> |
|
98 | <script src="reveal/js/reveal.min.js"></script> | |
102 |
|
99 | |||
103 | <script> |
|
100 | <script> | |
104 |
|
101 | |||
105 | // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration |
|
102 | // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration | |
106 | Reveal.initialize({ |
|
103 | Reveal.initialize({ | |
107 | controls: true, |
|
104 | controls: true, | |
108 | progress: true, |
|
105 | progress: true, | |
109 | history: true, |
|
106 | history: true, | |
110 |
|
107 | |||
111 | theme: Reveal.getQueryHash().theme, // available themes are in /css/theme |
|
108 | theme: Reveal.getQueryHash().theme, // available themes are in /css/theme | |
112 | transition: Reveal.getQueryHash().transition || 'page', // default/cube/page/concave/zoom/linear/none |
|
109 | transition: Reveal.getQueryHash().transition || 'page', // default/cube/page/concave/zoom/linear/none | |
113 |
|
110 | |||
114 | // Optional libraries used to extend on reveal.js |
|
111 | // Optional libraries used to extend on reveal.js | |
115 | dependencies: [ |
|
112 | dependencies: [ | |
116 | { src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } }, |
|
113 | { src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } }, | |
117 | { src: 'reveal/plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
114 | { src: 'reveal/plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, | |
118 | { src: 'reveal/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
115 | { src: 'reveal/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, | |
119 | { src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, |
|
116 | { src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, | |
120 | { src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }, |
|
117 | { src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }, | |
121 | { src: 'reveal/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }, |
|
118 | { src: 'reveal/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }, | |
122 | { src: 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', async: true }, |
|
119 | { src: 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', async: true }, | |
123 | { src: 'js/initmathjax.js', async: true} |
|
120 | { src: 'js/initmathjax.js', async: true} | |
124 | ] |
|
121 | ] | |
125 | }); |
|
122 | }); | |
126 | </script> |
|
123 | </script> | |
127 |
|
124 | |||
128 | <script> |
|
125 | <script> | |
129 | Reveal.addEventListener( 'slidechanged', function( event ) { |
|
126 | Reveal.addEventListener( 'slidechanged', function( event ) { | |
130 | MathJax.Hub.Rerender(); |
|
127 | MathJax.Hub.Rerender(); | |
131 | }); |
|
128 | }); | |
132 | </script> |
|
129 | </script> | |
133 |
|
130 | |||
134 | </body> |
|
131 | </body> | |
135 | </html> |
|
132 | </html> | |
136 | '''] |
|
133 | '''] | |
137 | return optional_footer_body |
|
134 | return optional_footer_body |
General Comments 0
You need to be logged in to leave comments.
Login now