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