Show More
@@ -1,57 +1,57 b'' | |||
|
1 | 1 | """HTML Exporter class""" |
|
2 | 2 | |
|
3 | 3 | # Copyright (c) IPython Development Team. |
|
4 | 4 | # Distributed under the terms of the Modified BSD License. |
|
5 | 5 | |
|
6 | 6 | import os |
|
7 | 7 | |
|
8 | 8 | from IPython.nbconvert.filters.highlight import Highlight2HTML |
|
9 | 9 | from IPython.config import Config |
|
10 | 10 | |
|
11 | 11 | from .templateexporter import TemplateExporter |
|
12 | 12 | |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | # Classes |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | class HTMLExporter(TemplateExporter): |
|
18 | 18 | """ |
|
19 | 19 | Exports a basic HTML document. This exporter assists with the export of |
|
20 | 20 | HTML. Inherit from it if you are writing your own HTML template and need |
|
21 | 21 | custom preprocessors/filters. If you don't need custom preprocessors/ |
|
22 | 22 | filters, just change the 'template_file' config option. |
|
23 | 23 | """ |
|
24 | 24 | |
|
25 | 25 | def _file_extension_default(self): |
|
26 | 26 | return '.html' |
|
27 | 27 | |
|
28 | 28 | def _default_template_path_default(self): |
|
29 | 29 | return os.path.join("..", "templates", "html") |
|
30 | 30 | |
|
31 | 31 | def _template_file_default(self): |
|
32 | 32 | return 'full' |
|
33 | 33 | |
|
34 | 34 | output_mimetype = 'text/html' |
|
35 | 35 | |
|
36 | 36 | @property |
|
37 | 37 | def default_config(self): |
|
38 | 38 | c = Config({ |
|
39 | 39 | 'NbConvertBase': { |
|
40 |
'display_data_priority' : [' |
|
|
40 | 'display_data_priority' : ['application/javascript', 'text/html', 'text/markdown', 'application/pdf', 'image/svg+xml', 'text/latex', 'image/png', 'image/jpeg', 'text/plain'] | |
|
41 | 41 | }, |
|
42 | 42 | 'CSSHTMLHeaderPreprocessor':{ |
|
43 | 43 | 'enabled':True |
|
44 | 44 | }, |
|
45 | 45 | 'HighlightMagicsPreprocessor': { |
|
46 | 46 | 'enabled':True |
|
47 | 47 | } |
|
48 | 48 | }) |
|
49 | 49 | c.merge(super(HTMLExporter,self).default_config) |
|
50 | 50 | return c |
|
51 | 51 | |
|
52 | 52 | def from_notebook_node(self, nb, resources=None, **kw): |
|
53 | 53 | langinfo = nb.metadata.get('language_info', {}) |
|
54 | 54 | lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) |
|
55 | 55 | self.register_filter('highlight_code', |
|
56 | 56 | Highlight2HTML(pygments_lexer=lexer, parent=self)) |
|
57 | 57 | return super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) |
@@ -1,198 +1,198 b'' | |||
|
1 | 1 | {%- extends 'display_priority.tpl' -%} |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | {% block codecell %} |
|
5 | 5 | <div class="cell border-box-sizing code_cell rendered"> |
|
6 | 6 | {{ super() }} |
|
7 | 7 | </div> |
|
8 | 8 | {%- endblock codecell %} |
|
9 | 9 | |
|
10 | 10 | {% block input_group -%} |
|
11 | 11 | <div class="input"> |
|
12 | 12 | {{ super() }} |
|
13 | 13 | </div> |
|
14 | 14 | {% endblock input_group %} |
|
15 | 15 | |
|
16 | 16 | {% block output_group %} |
|
17 | 17 | <div class="output_wrapper"> |
|
18 | 18 | <div class="output"> |
|
19 | 19 | {{ super() }} |
|
20 | 20 | </div> |
|
21 | 21 | </div> |
|
22 | 22 | {% endblock output_group %} |
|
23 | 23 | |
|
24 | 24 | {% block in_prompt -%} |
|
25 | 25 | <div class="prompt input_prompt"> |
|
26 | 26 | {%- if cell.execution_count is defined -%} |
|
27 | 27 | In [{{ cell.execution_count|replace(None, " ") }}]: |
|
28 | 28 | {%- else -%} |
|
29 | 29 | In [ ]: |
|
30 | 30 | {%- endif -%} |
|
31 | 31 | </div> |
|
32 | 32 | {%- endblock in_prompt %} |
|
33 | 33 | |
|
34 | 34 | {% block empty_in_prompt -%} |
|
35 | 35 | <div class="prompt input_prompt"> |
|
36 | 36 | </div> |
|
37 | 37 | {%- endblock empty_in_prompt %} |
|
38 | 38 | |
|
39 | 39 | {# |
|
40 | 40 | output_prompt doesn't do anything in HTML, |
|
41 | 41 | because there is a prompt div in each output area (see output block) |
|
42 | 42 | #} |
|
43 | 43 | {% block output_prompt %} |
|
44 | 44 | {% endblock output_prompt %} |
|
45 | 45 | |
|
46 | 46 | {% block input %} |
|
47 | 47 | <div class="inner_cell"> |
|
48 | 48 | <div class="input_area"> |
|
49 | 49 | {{ cell.source | highlight_code(metadata=cell.metadata) }} |
|
50 | 50 | </div> |
|
51 | 51 | </div> |
|
52 | 52 | {%- endblock input %} |
|
53 | 53 | |
|
54 | 54 | {% block output %} |
|
55 | 55 | <div class="output_area"> |
|
56 | 56 | {%- if output.output_type == 'execute_result' -%} |
|
57 | 57 | <div class="prompt output_prompt"> |
|
58 | 58 | {%- if cell.execution_count is defined -%} |
|
59 | 59 | Out[{{ cell.execution_count|replace(None, " ") }}]: |
|
60 | 60 | {%- else -%} |
|
61 | 61 | Out[ ]: |
|
62 | 62 | {%- endif -%} |
|
63 | 63 | {%- else -%} |
|
64 | 64 | <div class="prompt"> |
|
65 | 65 | {%- endif -%} |
|
66 | 66 | </div> |
|
67 | 67 | {{ super() }} |
|
68 | 68 | </div> |
|
69 | 69 | {% endblock output %} |
|
70 | 70 | |
|
71 | 71 | {% block markdowncell scoped %} |
|
72 | 72 | <div class="cell border-box-sizing text_cell rendered"> |
|
73 | 73 | {{ self.empty_in_prompt() }} |
|
74 | 74 | <div class="inner_cell"> |
|
75 | 75 | <div class="text_cell_render border-box-sizing rendered_html"> |
|
76 | 76 | {{ cell.source | markdown2html | strip_files_prefix }} |
|
77 | 77 | </div> |
|
78 | 78 | </div> |
|
79 | 79 | </div> |
|
80 | 80 | {%- endblock markdowncell %} |
|
81 | 81 | |
|
82 | 82 | {% block unknowncell scoped %} |
|
83 | 83 | unknown type {{ cell.type }} |
|
84 | 84 | {% endblock unknowncell %} |
|
85 | 85 | |
|
86 | 86 | {% block execute_result -%} |
|
87 | 87 | {%- set extra_class="output_execute_result" -%} |
|
88 | 88 | {% block data_priority scoped %} |
|
89 | 89 | {{ super() }} |
|
90 | 90 | {% endblock %} |
|
91 | 91 | {%- set extra_class="" -%} |
|
92 | 92 | {%- endblock execute_result %} |
|
93 | 93 | |
|
94 | 94 | {% block stream_stdout -%} |
|
95 | 95 | <div class="output_subarea output_stream output_stdout output_text"> |
|
96 | 96 | <pre> |
|
97 | 97 | {{- output.text | ansi2html -}} |
|
98 | 98 | </pre> |
|
99 | 99 | </div> |
|
100 | 100 | {%- endblock stream_stdout %} |
|
101 | 101 | |
|
102 | 102 | {% block stream_stderr -%} |
|
103 | 103 | <div class="output_subarea output_stream output_stderr output_text"> |
|
104 | 104 | <pre> |
|
105 | 105 | {{- output.text | ansi2html -}} |
|
106 | 106 | </pre> |
|
107 | 107 | </div> |
|
108 | 108 | {%- endblock stream_stderr %} |
|
109 | 109 | |
|
110 | 110 | {% block data_svg scoped -%} |
|
111 | 111 | <div class="output_svg output_subarea {{extra_class}}"> |
|
112 | 112 | {%- if output.svg_filename %} |
|
113 | 113 | <img src="{{output.svg_filename | posix_path}}" |
|
114 | 114 | {%- else %} |
|
115 | 115 | {{ output.data['image/svg+xml'] }} |
|
116 | 116 | {%- endif %} |
|
117 | 117 | </div> |
|
118 | 118 | {%- endblock data_svg %} |
|
119 | 119 | |
|
120 | 120 | {% block data_html scoped -%} |
|
121 | 121 | <div class="output_html rendered_html output_subarea {{extra_class}}"> |
|
122 | 122 | {{ output.data['text/html'] }} |
|
123 | 123 | </div> |
|
124 | 124 | {%- endblock data_html %} |
|
125 | 125 | |
|
126 | 126 | {% block data_markdown scoped -%} |
|
127 | 127 | <div class="output_markdown rendered_html output_subarea {{extra_class}}"> |
|
128 | 128 | {{ output.data['text/markdown'] | markdown2html }} |
|
129 | 129 | </div> |
|
130 | 130 | {%- endblock data_markdown %} |
|
131 | 131 | |
|
132 | 132 | {% block data_png scoped %} |
|
133 | 133 | <div class="output_png output_subarea {{extra_class}}"> |
|
134 | 134 | {%- if 'image/png' in output.metadata.get('filenames', {}) %} |
|
135 | 135 | <img src="{{output.metadata.filenames['image/png'] | posix_path}}" |
|
136 | 136 | {%- else %} |
|
137 | 137 | <img src="data:image/png;base64,{{ output.data['image/png'] }}" |
|
138 | 138 | {%- endif %} |
|
139 | 139 | {%- if 'width' in output.metadata.get('image/png', {}) %} |
|
140 | 140 | width={{output.metadata['image/png']['width']}} |
|
141 | 141 | {%- endif %} |
|
142 | 142 | {%- if 'height' in output.metadata.get('image/png', {}) %} |
|
143 | 143 | height={{output.metadata['image/png']['height']}} |
|
144 | 144 | {%- endif %} |
|
145 | 145 | > |
|
146 | 146 | </div> |
|
147 | 147 | {%- endblock data_png %} |
|
148 | 148 | |
|
149 | 149 | {% block data_jpg scoped %} |
|
150 | 150 | <div class="output_jpeg output_subarea {{extra_class}}"> |
|
151 | 151 | {%- if 'image/jpeg' in output.metadata.get('filenames', {}) %} |
|
152 | 152 | <img src="{{output.metadata.filenames['image/jpeg'] | posix_path}}" |
|
153 | 153 | {%- else %} |
|
154 | 154 | <img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}" |
|
155 | 155 | {%- endif %} |
|
156 | 156 | {%- if 'width' in output.metadata.get('image/jpeg', {}) %} |
|
157 | 157 | width={{output.metadata['image/jpeg']['width']}} |
|
158 | 158 | {%- endif %} |
|
159 | 159 | {%- if 'height' in output.metadata.get('image/jpeg', {}) %} |
|
160 | 160 | height={{output.metadata['image/jpeg']['height']}} |
|
161 | 161 | {%- endif %} |
|
162 | 162 | > |
|
163 | 163 | </div> |
|
164 | 164 | {%- endblock data_jpg %} |
|
165 | 165 | |
|
166 | 166 | {% block data_latex scoped %} |
|
167 | 167 | <div class="output_latex output_subarea {{extra_class}}"> |
|
168 | 168 | {{ output.data['text/latex'] }} |
|
169 | 169 | </div> |
|
170 | 170 | {%- endblock data_latex %} |
|
171 | 171 | |
|
172 | 172 | {% block error -%} |
|
173 | 173 | <div class="output_subarea output_text output_error"> |
|
174 | 174 | <pre> |
|
175 | 175 | {{- super() -}} |
|
176 | 176 | </pre> |
|
177 | 177 | </div> |
|
178 | 178 | {%- endblock error %} |
|
179 | 179 | |
|
180 | 180 | {%- block traceback_line %} |
|
181 | 181 | {{ line | ansi2html }} |
|
182 | 182 | {%- endblock traceback_line %} |
|
183 | 183 | |
|
184 | 184 | {%- block data_text scoped %} |
|
185 | 185 | <div class="output_text output_subarea {{extra_class}}"> |
|
186 | 186 | <pre> |
|
187 | 187 | {{- output.data['text/plain'] | ansi2html -}} |
|
188 | 188 | </pre> |
|
189 | 189 | </div> |
|
190 | 190 | {%- endblock -%} |
|
191 | 191 | |
|
192 | 192 | {%- block data_javascript scoped %} |
|
193 | 193 | <div class="output_subarea output_javascript {{extra_class}}"> |
|
194 | 194 | <script type="text/javascript"> |
|
195 |
{{ output.data[' |
|
|
195 | {{ output.data['application/javascript'] }} | |
|
196 | 196 | </script> |
|
197 | 197 | </div> |
|
198 | 198 | {%- endblock -%} |
General Comments 0
You need to be logged in to leave comments.
Login now