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