##// END OF EJS Templates
support markdown output in nbconvert
Min RK -
Show More
@@ -1,66 +1,57 b''
1 1 """HTML Exporter class"""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2013, the IPython Development Team.
5 #
3 # Copyright (c) IPython Development Team.
6 4 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14 5
15 6 import os
16 7
17 8 from IPython.nbconvert.filters.highlight import Highlight2HTML
18 9 from IPython.config import Config
19 10
20 11 from .templateexporter import TemplateExporter
21 12
22 13 #-----------------------------------------------------------------------------
23 14 # Classes
24 15 #-----------------------------------------------------------------------------
25 16
26 17 class HTMLExporter(TemplateExporter):
27 18 """
28 19 Exports a basic HTML document. This exporter assists with the export of
29 20 HTML. Inherit from it if you are writing your own HTML template and need
30 21 custom preprocessors/filters. If you don't need custom preprocessors/
31 22 filters, just change the 'template_file' config option.
32 23 """
33 24
34 25 def _file_extension_default(self):
35 26 return '.html'
36 27
37 28 def _default_template_path_default(self):
38 29 return os.path.join("..", "templates", "html")
39 30
40 31 def _template_file_default(self):
41 32 return 'full'
42 33
43 34 output_mimetype = 'text/html'
44 35
45 36 @property
46 37 def default_config(self):
47 38 c = Config({
48 39 'NbConvertBase': {
49 'display_data_priority' : ['text/javascript', 'text/html', 'application/pdf', 'image/svg+xml', 'text/latex', 'image/png', 'image/jpeg', 'text/plain']
40 'display_data_priority' : ['text/javascript', 'text/html', 'text/markdown', 'application/pdf', 'image/svg+xml', 'text/latex', 'image/png', 'image/jpeg', 'text/plain']
50 41 },
51 42 'CSSHTMLHeaderPreprocessor':{
52 43 'enabled':True
53 44 },
54 45 'HighlightMagicsPreprocessor': {
55 46 'enabled':True
56 47 }
57 48 })
58 49 c.merge(super(HTMLExporter,self).default_config)
59 50 return c
60 51
61 52 def from_notebook_node(self, nb, resources=None, **kw):
62 53 langinfo = nb.metadata.get('language_info', {})
63 54 lexer = langinfo.get('pygments_lexer', langinfo.get('name', None))
64 55 self.register_filter('highlight_code',
65 56 Highlight2HTML(pygments_lexer=lexer, parent=self))
66 57 return super(HTMLExporter, self).from_notebook_node(nb, resources, **kw)
@@ -1,192 +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&nbsp;[{{ cell.execution_count|replace(None, "&nbsp;") }}]:
28 28 {%- else -%}
29 29 In&nbsp;[&nbsp;]:
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, "&nbsp;") }}]:
60 60 {%- else -%}
61 61 Out[&nbsp;]:
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 {% block data_markdown scoped -%}
127 <div class="output_markdown rendered_html output_subarea {{extra_class}}">
128 {{ output.data['text/markdown'] | markdown2html }}
129 </div>
130 {%- endblock data_markdown %}
131
126 132 {% block data_png scoped %}
127 133 <div class="output_png output_subarea {{extra_class}}">
128 134 {%- if 'image/png' in output.metadata.get('filenames', {}) %}
129 135 <img src="{{output.metadata.filenames['image/png'] | posix_path}}"
130 136 {%- else %}
131 137 <img src="data:image/png;base64,{{ output.data['image/png'] }}"
132 138 {%- endif %}
133 139 {%- if 'width' in output.metadata.get('image/png', {}) %}
134 140 width={{output.metadata['png']['width']}}
135 141 {%- endif %}
136 142 {%- if 'height' in output.metadata.get('image/png', {}) %}
137 143 height={{output.metadata['png']['height']}}
138 144 {%- endif %}
139 145 >
140 146 </div>
141 147 {%- endblock data_png %}
142 148
143 149 {% block data_jpg scoped %}
144 150 <div class="output_jpeg output_subarea {{extra_class}}">
145 151 {%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
146 152 <img src="{{output.metadata.filenames['image/jpeg'] | posix_path}}"
147 153 {%- else %}
148 154 <img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
149 155 {%- endif %}
150 156 {%- if 'width' in output.metadata.get('image/jpeg', {}) %}
151 157 width={{output.metadata['image/jpeg']['width']}}
152 158 {%- endif %}
153 159 {%- if 'height' in output.metadata.get('image/jpeg', {}) %}
154 160 height={{output.metadata['image/jpeg']['height']}}
155 161 {%- endif %}
156 162 >
157 163 </div>
158 164 {%- endblock data_jpg %}
159 165
160 166 {% block data_latex scoped %}
161 167 <div class="output_latex output_subarea {{extra_class}}">
162 168 {{ output.data['text/latex'] }}
163 169 </div>
164 170 {%- endblock data_latex %}
165 171
166 172 {% block error -%}
167 173 <div class="output_subarea output_text output_error">
168 174 <pre>
169 175 {{- super() -}}
170 176 </pre>
171 177 </div>
172 178 {%- endblock error %}
173 179
174 180 {%- block traceback_line %}
175 181 {{ line | ansi2html }}
176 182 {%- endblock traceback_line %}
177 183
178 184 {%- block data_text scoped %}
179 185 <div class="output_text output_subarea {{extra_class}}">
180 186 <pre>
181 187 {{- output.data['text/plain'] | ansi2html -}}
182 188 </pre>
183 189 </div>
184 190 {%- endblock -%}
185 191
186 192 {%- block data_javascript scoped %}
187 193 <div class="output_subarea output_javascript {{extra_class}}">
188 194 <script type="text/javascript">
189 195 {{ output.data['text/javascript'] }}
190 196 </script>
191 197 </div>
192 198 {%- endblock -%}
@@ -1,41 +1,44 b''
1 1 ((= Auto-generated template file, DO NOT edit directly!
2 2 To edit this file, please refer to ../../skeleton/README.md =))
3 3
4 4
5 5 ((*- extends 'null.tplx' -*))
6 6
7 7 ((=display data priority=))
8 8
9 9
10 10 ((*- block data_priority scoped -*))
11 11 ((*- for type in output.data | filter_data_type -*))
12 12 ((*- if type == 'application/pdf' -*))
13 13 ((*- block data_pdf -*))
14 14 ((*- endblock -*))
15 15 ((*- elif type == 'image/svg+xml' -*))
16 16 ((*- block data_svg -*))
17 17 ((*- endblock -*))
18 18 ((*- elif type == 'image/png' -*))
19 19 ((*- block data_png -*))
20 20 ((*- endblock -*))
21 21 ((*- elif type == 'text/html' -*))
22 22 ((*- block data_html -*))
23 23 ((*- endblock -*))
24 ((*- elif type == 'text/markdown' -*))
25 ((*- block data_markdown -*))
26 ((*- endblock -*))
24 27 ((*- elif type == 'image/jpeg' -*))
25 28 ((*- block data_jpg -*))
26 29 ((*- endblock -*))
27 30 ((*- elif type == 'text/plain' -*))
28 31 ((*- block data_text -*))
29 32 ((*- endblock -*))
30 33 ((*- elif type == 'text/latex' -*))
31 34 ((*- block data_latex -*))
32 35 ((*- endblock -*))
33 36 ((*- elif type == 'application/javascript' -*))
34 37 ((*- block data_javascript -*))
35 38 ((*- endblock -*))
36 39 ((*- else -*))
37 40 ((*- block data_other -*))
38 41 ((*- endblock -*))
39 42 ((*- endif -*))
40 43 ((*- endfor -*))
41 44 ((*- endblock data_priority -*))
@@ -1,63 +1,67 b''
1 1 {% extends 'display_priority.tpl' %}
2 2
3 3
4 4 {% block in_prompt %}
5 5 {% endblock in_prompt %}
6 6
7 7 {% block output_prompt %}
8 8 {%- endblock output_prompt %}
9 9
10 10 {% block input %}
11 11 {{ cell.source | indent(4)}}
12 12 {% endblock input %}
13 13
14 14 {% block error %}
15 15 {{ super() }}
16 16 {% endblock error %}
17 17
18 18 {% block traceback_line %}
19 19 {{ line | indent | strip_ansi }}
20 20 {% endblock traceback_line %}
21 21
22 22 {% block execute_result %}
23 23
24 24 {% block data_priority scoped %}
25 25 {{ super() }}
26 26 {% endblock %}
27 27 {% endblock execute_result %}
28 28
29 29 {% block stream %}
30 30 {{ output.text | indent }}
31 31 {% endblock stream %}
32 32
33 33 {% block data_svg %}
34 34 ![svg]({{ output.svg_filename | path2url }})
35 35 {% endblock data_svg %}
36 36
37 37 {% block data_png %}
38 38 ![png]({{ output.metadata.filenames['image/png'] | path2url }})
39 39 {% endblock data_png %}
40 40
41 41 {% block data_jpg %}
42 42 ![jpeg]({{ output.metadata.filenames['image/jpeg'] | path2url }})
43 43 {% endblock data_jpg %}
44 44
45 45 {% block data_latex %}
46 46 {{ output.data['text/latex'] }}
47 47 {% endblock data_latex %}
48 48
49 49 {% block data_html scoped %}
50 50 {{ output.data['text/html'] }}
51 51 {% endblock data_html %}
52 52
53 {% block data_markdown scoped %}
54 {{ output.data['text/markdown'] }}
55 {% endblock data_markdown %}
56
53 57 {% block data_text scoped %}
54 58 {{ output.data['text/plain'] | indent }}
55 59 {% endblock data_text %}
56 60
57 61 {% block markdowncell scoped %}
58 62 {{ cell.source }}
59 63 {% endblock markdowncell %}
60 64
61 65 {% block unknowncell scoped %}
62 66 unknown type {{ cell.type }}
63 67 {% endblock unknowncell %} No newline at end of file
@@ -1,37 +1,40 b''
1 1 {%- extends 'null.tpl' -%}
2 2
3 3 {#display data priority#}
4 4
5 5
6 6 {%- block data_priority scoped -%}
7 7 {%- for type in output.data | filter_data_type -%}
8 8 {%- if type == 'application/pdf' -%}
9 9 {%- block data_pdf -%}
10 10 {%- endblock -%}
11 11 {%- elif type == 'image/svg+xml' -%}
12 12 {%- block data_svg -%}
13 13 {%- endblock -%}
14 14 {%- elif type == 'image/png' -%}
15 15 {%- block data_png -%}
16 16 {%- endblock -%}
17 17 {%- elif type == 'text/html' -%}
18 18 {%- block data_html -%}
19 19 {%- endblock -%}
20 {%- elif type == 'text/markdown' -%}
21 {%- block data_markdown -%}
22 {%- endblock -%}
20 23 {%- elif type == 'image/jpeg' -%}
21 24 {%- block data_jpg -%}
22 25 {%- endblock -%}
23 26 {%- elif type == 'text/plain' -%}
24 27 {%- block data_text -%}
25 28 {%- endblock -%}
26 29 {%- elif type == 'text/latex' -%}
27 30 {%- block data_latex -%}
28 31 {%- endblock -%}
29 32 {%- elif type == 'application/javascript' -%}
30 33 {%- block data_javascript -%}
31 34 {%- endblock -%}
32 35 {%- else -%}
33 36 {%- block data_other -%}
34 37 {%- endblock -%}
35 38 {%- endif -%}
36 39 {%- endfor -%}
37 40 {%- endblock data_priority -%}
General Comments 0
You need to be logged in to leave comments. Login now