##// END OF EJS Templates
propagate raw_mimetype to nbconvert
MinRK -
Show More
@@ -1,56 +1,56 b''
1 1 """HTML Exporter class"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 from IPython.utils.traitlets import Unicode, List
16 16
17 17 from IPython.nbconvert import preprocessors
18 18 from IPython.config import Config
19 19
20 20 from .templateexporter import TemplateExporter
21 21
22 22 #-----------------------------------------------------------------------------
23 23 # Classes
24 24 #-----------------------------------------------------------------------------
25 25
26 26 class HTMLExporter(TemplateExporter):
27 27 """
28 28 Exports a basic HTML document. This exporter assists with the export of
29 29 HTML. Inherit from it if you are writing your own HTML template and need
30 30 custom preprocessors/filters. If you don't need custom preprocessors/
31 31 filters, just change the 'template_file' config option.
32 32 """
33 33
34 34 file_extension = Unicode(
35 35 'html', config=True,
36 36 help="Extension of the file that should be written to disk"
37 37 )
38 38
39 39 default_template = Unicode('full', config=True, help="""Flavor of the data
40 40 format to use. I.E. 'full' or 'basic'""")
41 41
42 def _raw_format_default(self):
43 return 'html'
42 def _raw_mimetype_default(self):
43 return 'text/html'
44 44
45 45 @property
46 46 def default_config(self):
47 47 c = Config({
48 48 'CSSHTMLHeaderPreprocessor':{
49 49 'enabled':True
50 50 },
51 51 'HighlightMagicsPreprocessor': {
52 52 'enabled':True
53 53 }
54 54 })
55 55 c.merge(super(HTMLExporter,self).default_config)
56 56 return c
@@ -1,93 +1,93 b''
1 1 """LaTeX Exporter class"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 # Stdlib imports
16 16 import os
17 17
18 18 # IPython imports
19 19 from IPython.utils.traitlets import Unicode, List
20 20 from IPython.config import Config
21 21
22 22 from IPython.nbconvert import filters, preprocessors
23 23 from .templateexporter import TemplateExporter
24 24
25 25 #-----------------------------------------------------------------------------
26 26 # Classes and functions
27 27 #-----------------------------------------------------------------------------
28 28
29 29 class LatexExporter(TemplateExporter):
30 30 """
31 31 Exports to a Latex template. Inherit from this class if your template is
32 32 LaTeX based and you need custom tranformers/filters. Inherit from it if
33 33 you are writing your own HTML template and need custom tranformers/filters.
34 34 If you don't need custom tranformers/filters, just change the
35 35 'template_file' config option. Place your template in the special "/latex"
36 36 subfolder of the "../templates" folder.
37 37 """
38 38
39 39 file_extension = Unicode(
40 40 'tex', config=True,
41 41 help="Extension of the file that should be written to disk")
42 42
43 43 default_template = Unicode('article', config=True, help="""Template of the
44 44 data format to use. I.E. 'article' or 'report'""")
45 45
46 46 #Latex constants
47 47 default_template_path = Unicode(
48 48 os.path.join("..", "templates", "latex"), config=True,
49 49 help="Path where the template files are located.")
50 50
51 51 template_skeleton_path = Unicode(
52 52 os.path.join("..", "templates", "latex", "skeleton"), config=True,
53 53 help="Path where the template skeleton files are located.")
54 54
55 55 #Special Jinja2 syntax that will not conflict when exporting latex.
56 56 jinja_comment_block_start = Unicode("((=", config=True)
57 57 jinja_comment_block_end = Unicode("=))", config=True)
58 58 jinja_variable_block_start = Unicode("(((", config=True)
59 59 jinja_variable_block_end = Unicode(")))", config=True)
60 60 jinja_logic_block_start = Unicode("((*", config=True)
61 61 jinja_logic_block_end = Unicode("*))", config=True)
62 62
63 63 #Extension that the template files use.
64 64 template_extension = Unicode(".tplx", config=True)
65 65
66 def _raw_format_default(self):
67 return 'latex'
66 def _raw_mimetype_default(self):
67 return 'text/latex'
68 68
69 69
70 70 @property
71 71 def default_config(self):
72 72 c = Config({
73 73 'NbConvertBase': {
74 74 'display_data_priority' : ['latex', 'pdf', 'png', 'jpg', 'svg', 'jpeg', 'text']
75 75 },
76 76 'ExtractOutputPreprocessor': {
77 77 'enabled':True
78 78 },
79 79 'SVG2PDFPreprocessor': {
80 80 'enabled':True
81 81 },
82 82 'LatexPreprocessor': {
83 83 'enabled':True
84 84 },
85 85 'SphinxPreprocessor': {
86 86 'enabled':True
87 87 },
88 88 'HighlightMagicsPreprocessor': {
89 89 'enabled':True
90 90 }
91 91 })
92 92 c.merge(super(LatexExporter,self).default_config)
93 93 return c
@@ -1,43 +1,43 b''
1 1 """Markdown Exporter class"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 from IPython.config import Config
16 16 from IPython.utils.traitlets import Unicode
17 17
18 18 from .templateexporter import TemplateExporter
19 19
20 20 #-----------------------------------------------------------------------------
21 21 # Classes
22 22 #-----------------------------------------------------------------------------
23 23
24 24 class MarkdownExporter(TemplateExporter):
25 25 """
26 26 Exports to a markdown document (.md)
27 27 """
28 28
29 29 file_extension = Unicode(
30 30 'md', config=True,
31 31 help="Extension of the file that should be written to disk")
32 32
33 def _raw_format_default(self):
34 return 'markdown'
33 def _raw_mimetype_default(self):
34 return 'text/markdown'
35 35
36 def _raw_formats_default(self):
37 return ['md', 'markdown', 'html']
36 def _raw_mimetypes_default(self):
37 return ['text/markdown', 'text/html']
38 38
39 39 @property
40 40 def default_config(self):
41 41 c = Config({'ExtractOutputPreprocessor':{'enabled':True}})
42 42 c.merge(super(MarkdownExporter,self).default_config)
43 43 return c
@@ -1,37 +1,34 b''
1 1 """Python script Exporter class"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 from IPython.utils.traitlets import Unicode
16 16
17 17 from .templateexporter import TemplateExporter
18 18
19 19 #-----------------------------------------------------------------------------
20 20 # Classes
21 21 #-----------------------------------------------------------------------------
22 22
23 23 class PythonExporter(TemplateExporter):
24 24 """
25 25 Exports a Python code file.
26 26 """
27 27
28 28 file_extension = Unicode(
29 29 'py', config=True,
30 30 help="Extension of the file that should be written to disk")
31 31
32 def _raw_format_default(self):
33 return 'python'
34
35 def _raw_formats_default(self):
36 return ['py', 'python']
32 def _raw_mimetype_default(self):
33 return 'application/x-python'
37 34
@@ -1,43 +1,40 b''
1 1 """restructuredText Exporter class"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 from IPython.utils.traitlets import Unicode
16 16 from IPython.config import Config
17 17
18 18 from .templateexporter import TemplateExporter
19 19
20 20 #-----------------------------------------------------------------------------
21 21 # Classes
22 22 #-----------------------------------------------------------------------------
23 23
24 24 class RSTExporter(TemplateExporter):
25 25 """
26 26 Exports restructured text documents.
27 27 """
28 28
29 29 file_extension = Unicode(
30 30 'rst', config=True,
31 31 help="Extension of the file that should be written to disk")
32 32
33 def _raw_format_default(self):
34 return 'rst'
33 def _raw_mimetype_default(self):
34 return 'text/restructuredtext'
35 35
36 def _raw_formats_default(self):
37 return ['rst', 'restructuredtext']
38
39 36 @property
40 37 def default_config(self):
41 38 c = Config({'ExtractOutputPreprocessor':{'enabled':True}})
42 39 c.merge(super(RSTExporter,self).default_config)
43 40 return c
@@ -1,324 +1,324 b''
1 1 """This module defines TemplateExporter, a highly configurable converter
2 2 that uses Jinja2 to export notebook files into different formats.
3 3 """
4 4
5 5 #-----------------------------------------------------------------------------
6 6 # Copyright (c) 2013, the IPython Development Team.
7 7 #
8 8 # Distributed under the terms of the Modified BSD License.
9 9 #
10 10 # The full license is in the file COPYING.txt, distributed with this software.
11 11 #-----------------------------------------------------------------------------
12 12
13 13 #-----------------------------------------------------------------------------
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16 16
17 17 from __future__ import print_function, absolute_import
18 18
19 19 # Stdlib imports
20 20 import os
21 21
22 22 # other libs/dependencies
23 23 from jinja2 import Environment, FileSystemLoader, ChoiceLoader, TemplateNotFound
24 24
25 25 # IPython imports
26 26 from IPython.utils.traitlets import MetaHasTraits, Unicode, List, Dict, Any
27 27 from IPython.utils.importstring import import_item
28 28 from IPython.utils import py3compat, text
29 29
30 30 from IPython.nbformat.current import docstring_nbformat_mod
31 31 from IPython.nbconvert import filters
32 32 from .exporter import Exporter
33 33
34 34 #-----------------------------------------------------------------------------
35 35 # Globals and constants
36 36 #-----------------------------------------------------------------------------
37 37
38 38 #Jinja2 extensions to load.
39 39 JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols']
40 40
41 41 default_filters = {
42 42 'indent': text.indent,
43 43 'markdown2html': filters.markdown2html,
44 44 'ansi2html': filters.ansi2html,
45 45 'filter_data_type': filters.DataTypeFilter,
46 46 'get_lines': filters.get_lines,
47 47 'highlight2html': filters.Highlight2Html,
48 48 'highlight2latex': filters.Highlight2Latex,
49 49 'ipython2python': filters.ipython2python,
50 50 'posix_path': filters.posix_path,
51 51 'markdown2latex': filters.markdown2latex,
52 52 'markdown2rst': filters.markdown2rst,
53 53 'comment_lines': filters.comment_lines,
54 54 'strip_ansi': filters.strip_ansi,
55 55 'strip_dollars': filters.strip_dollars,
56 56 'strip_files_prefix': filters.strip_files_prefix,
57 57 'html2text' : filters.html2text,
58 58 'add_anchor': filters.add_anchor,
59 59 'ansi2latex': filters.ansi2latex,
60 60 'wrap_text': filters.wrap_text,
61 61 'escape_latex': filters.escape_latex,
62 62 'citation2latex': filters.citation2latex,
63 63 'path2url': filters.path2url,
64 64 'add_prompts': filters.add_prompts,
65 65 }
66 66
67 67 #-----------------------------------------------------------------------------
68 68 # Class
69 69 #-----------------------------------------------------------------------------
70 70
71 71 class TemplateExporter(Exporter):
72 72 """
73 73 Exports notebooks into other file formats. Uses Jinja 2 templating engine
74 74 to output new formats. Inherit from this class if you are creating a new
75 75 template type along with new filters/preprocessors. If the filters/
76 76 preprocessors provided by default suffice, there is no need to inherit from
77 77 this class. Instead, override the template_file and file_extension
78 78 traits via a config file.
79 79
80 80 {filters}
81 81 """
82 82
83 83 # finish the docstring
84 84 __doc__ = __doc__.format(filters = '- '+'\n - '.join(default_filters.keys()))
85 85
86 86
87 87 template_file = Unicode(u'default',
88 88 config=True,
89 89 help="Name of the template file to use")
90 90 def _template_file_changed(self, name, old, new):
91 91 if new == 'default':
92 92 self.template_file = self.default_template
93 93 else:
94 94 self.template_file = new
95 95 self.template = None
96 96 self._load_template()
97 97
98 98 default_template = Unicode(u'')
99 99 template = Any()
100 100 environment = Any()
101 101
102 102 template_path = List(['.'], config=True)
103 103 def _template_path_changed(self, name, old, new):
104 104 self._load_template()
105 105
106 106 default_template_path = Unicode(
107 107 os.path.join("..", "templates"),
108 108 help="Path where the template files are located.")
109 109
110 110 template_skeleton_path = Unicode(
111 111 os.path.join("..", "templates", "skeleton"),
112 112 help="Path where the template skeleton files are located.")
113 113
114 114 #Jinja block definitions
115 115 jinja_comment_block_start = Unicode("", config=True)
116 116 jinja_comment_block_end = Unicode("", config=True)
117 117 jinja_variable_block_start = Unicode("", config=True)
118 118 jinja_variable_block_end = Unicode("", config=True)
119 119 jinja_logic_block_start = Unicode("", config=True)
120 120 jinja_logic_block_end = Unicode("", config=True)
121 121
122 122 #Extension that the template files use.
123 123 template_extension = Unicode(".tpl", config=True)
124 124
125 125 filters = Dict(config=True,
126 126 help="""Dictionary of filters, by name and namespace, to add to the Jinja
127 127 environment.""")
128 128
129 raw_format = Unicode('')
130 raw_formats = List(config=True,
129 raw_mimetype = Unicode('')
130 raw_mimetypes = List(config=True,
131 131 help="""formats of raw cells to be included in this Exporter's output."""
132 132 )
133 def _raw_formats_default(self):
134 return [self.raw_format]
133 def _raw_mimetypes_default(self):
134 return [self.raw_mimetype]
135 135
136 136
137 137 def __init__(self, config=None, extra_loaders=None, **kw):
138 138 """
139 139 Public constructor
140 140
141 141 Parameters
142 142 ----------
143 143 config : config
144 144 User configuration instance.
145 145 extra_loaders : list[of Jinja Loaders]
146 146 ordered list of Jinja loader to find templates. Will be tried in order
147 147 before the default FileSystem ones.
148 148 template : str (optional, kw arg)
149 149 Template to use when exporting.
150 150 """
151 151 super(TemplateExporter, self).__init__(config=config, **kw)
152 152
153 153 #Init
154 154 self._init_template()
155 155 self._init_environment(extra_loaders=extra_loaders)
156 156 self._init_preprocessors()
157 157 self._init_filters()
158 158
159 159
160 160 def _load_template(self):
161 161 """Load the Jinja template object from the template file
162 162
163 163 This is a no-op if the template attribute is already defined,
164 164 or the Jinja environment is not setup yet.
165 165
166 166 This is triggered by various trait changes that would change the template.
167 167 """
168 168 if self.template is not None:
169 169 return
170 170 # called too early, do nothing
171 171 if self.environment is None:
172 172 return
173 173 # Try different template names during conversion. First try to load the
174 174 # template by name with extension added, then try loading the template
175 175 # as if the name is explicitly specified, then try the name as a
176 176 # 'flavor', and lastly just try to load the template by module name.
177 177 module_name = self.__module__.rsplit('.', 1)[-1]
178 178 try_names = []
179 179 if self.template_file:
180 180 try_names.extend([
181 181 self.template_file + self.template_extension,
182 182 self.template_file,
183 183 module_name + '_' + self.template_file + self.template_extension,
184 184 ])
185 185 try_names.append(module_name + self.template_extension)
186 186 for try_name in try_names:
187 187 self.log.debug("Attempting to load template %s", try_name)
188 188 try:
189 189 self.template = self.environment.get_template(try_name)
190 190 except (TemplateNotFound, IOError):
191 191 pass
192 192 except Exception as e:
193 193 self.log.warn("Unexpected exception loading template: %s", try_name, exc_info=True)
194 194 else:
195 195 self.log.info("Loaded template %s", try_name)
196 196 break
197 197
198 198 @docstring_nbformat_mod
199 199 def from_notebook_node(self, nb, resources=None, **kw):
200 200 """
201 201 Convert a notebook from a notebook node instance.
202 202
203 203 Parameters
204 204 ----------
205 205 nb : :class:`~{nbformat_mod}.nbbase.NotebookNode`
206 206 Notebook node
207 207 resources : dict
208 208 Additional resources that can be accessed read/write by
209 209 preprocessors and filters.
210 210 """
211 211 nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw)
212 resources.setdefault('raw_format', self.raw_format)
213 resources.setdefault('raw_formats', self.raw_formats)
212 resources.setdefault('raw_mimetype', self.raw_mimetype)
213 resources.setdefault('raw_mimetypes', self.raw_mimetypes)
214 214
215 215 self._load_template()
216 216
217 217 if self.template is not None:
218 218 output = self.template.render(nb=nb_copy, resources=resources)
219 219 else:
220 220 raise IOError('template file "%s" could not be found' % self.template_file)
221 221 return output, resources
222 222
223 223
224 224 def register_filter(self, name, jinja_filter):
225 225 """
226 226 Register a filter.
227 227 A filter is a function that accepts and acts on one string.
228 228 The filters are accesible within the Jinja templating engine.
229 229
230 230 Parameters
231 231 ----------
232 232 name : str
233 233 name to give the filter in the Jinja engine
234 234 filter : filter
235 235 """
236 236 if jinja_filter is None:
237 237 raise TypeError('filter')
238 238 isclass = isinstance(jinja_filter, type)
239 239 constructed = not isclass
240 240
241 241 #Handle filter's registration based on it's type
242 242 if constructed and isinstance(jinja_filter, py3compat.string_types):
243 243 #filter is a string, import the namespace and recursively call
244 244 #this register_filter method
245 245 filter_cls = import_item(jinja_filter)
246 246 return self.register_filter(name, filter_cls)
247 247
248 248 if constructed and hasattr(jinja_filter, '__call__'):
249 249 #filter is a function, no need to construct it.
250 250 self.environment.filters[name] = jinja_filter
251 251 return jinja_filter
252 252
253 253 elif isclass and isinstance(jinja_filter, MetaHasTraits):
254 254 #filter is configurable. Make sure to pass in new default for
255 255 #the enabled flag if one was specified.
256 256 filter_instance = jinja_filter(parent=self)
257 257 self.register_filter(name, filter_instance )
258 258
259 259 elif isclass:
260 260 #filter is not configurable, construct it
261 261 filter_instance = jinja_filter()
262 262 self.register_filter(name, filter_instance)
263 263
264 264 else:
265 265 #filter is an instance of something without a __call__
266 266 #attribute.
267 267 raise TypeError('filter')
268 268
269 269
270 270 def _init_template(self):
271 271 """
272 272 Make sure a template name is specified. If one isn't specified, try to
273 273 build one from the information we know.
274 274 """
275 275 self._template_file_changed('template_file', self.template_file, self.template_file)
276 276
277 277
278 278 def _init_environment(self, extra_loaders=None):
279 279 """
280 280 Create the Jinja templating environment.
281 281 """
282 282 here = os.path.dirname(os.path.realpath(__file__))
283 283 loaders = []
284 284 if extra_loaders:
285 285 loaders.extend(extra_loaders)
286 286
287 287 paths = self.template_path
288 288 paths.extend([os.path.join(here, self.default_template_path),
289 289 os.path.join(here, self.template_skeleton_path)])
290 290 loaders.append(FileSystemLoader(paths))
291 291
292 292 self.environment = Environment(
293 293 loader= ChoiceLoader(loaders),
294 294 extensions=JINJA_EXTENSIONS
295 295 )
296 296
297 297 #Set special Jinja2 syntax that will not conflict with latex.
298 298 if self.jinja_logic_block_start:
299 299 self.environment.block_start_string = self.jinja_logic_block_start
300 300 if self.jinja_logic_block_end:
301 301 self.environment.block_end_string = self.jinja_logic_block_end
302 302 if self.jinja_variable_block_start:
303 303 self.environment.variable_start_string = self.jinja_variable_block_start
304 304 if self.jinja_variable_block_end:
305 305 self.environment.variable_end_string = self.jinja_variable_block_end
306 306 if self.jinja_comment_block_start:
307 307 self.environment.comment_start_string = self.jinja_comment_block_start
308 308 if self.jinja_comment_block_end:
309 309 self.environment.comment_end_string = self.jinja_comment_block_end
310 310
311 311
312 312 def _init_filters(self):
313 313 """
314 314 Register all of the filters required for the exporter.
315 315 """
316 316
317 317 #Add default filters to the Jinja2 environment
318 318 for key, value in default_filters.items():
319 319 self.register_filter(key, value)
320 320
321 321 #Load user filters. Overwrite existing filters if need be.
322 322 if self.filters:
323 323 for key, user_filter in self.filters.items():
324 324 self.register_filter(key, user_filter)
@@ -1,48 +1,54 b''
1 1 """Base TestCase class for testing Exporters"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 import os
16 16
17 17 from IPython.testing.decorators import onlyif_cmds_exist
18 18
19 19 from ...tests.base import TestsBase
20 20
21 21 #-----------------------------------------------------------------------------
22 22 # Class
23 23 #-----------------------------------------------------------------------------
24 24
25 all_raw_formats = set(['markdown', 'html', 'rst', 'python', 'latex'])
25 all_raw_mimetypes = {
26 'application/x-python',
27 'text/markdown',
28 'text/html',
29 'text/restructuredtext',
30 'text/latex',
31 }
26 32
27 33 class ExportersTestsBase(TestsBase):
28 34 """Contains base test functions for exporters"""
29 35
30 36 exporter_class = None
31 37 should_include_raw = None
32 38
33 39 def _get_notebook(self, nb_name='notebook2.ipynb'):
34 40 return os.path.join(self._get_files_path(), nb_name)
35 41
36 42 @onlyif_cmds_exist('pandoc')
37 43 def test_raw_cell_inclusion(self):
38 """test raw cell inclusion based on raw_format metadata"""
44 """test raw cell inclusion based on raw_mimetype metadata"""
39 45 if self.should_include_raw is None:
40 46 return
41 47 exporter = self.exporter_class()
42 48 (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb'))
43 49 for inc in self.should_include_raw:
44 50 self.assertIn('raw %s' % inc, output, "should include %s" % inc)
45 self.assertIn('no raw_format metadata', output)
46 for exc in all_raw_formats.difference(self.should_include_raw):
51 self.assertIn('no raw_mimetype metadata', output)
52 for exc in all_raw_mimetypes.difference(self.should_include_raw):
47 53 self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc)
48 54 self.assertNotIn('never be included', output)
@@ -1,84 +1,84 b''
1 1 {
2 2 "metadata": {
3 3 "name": ""
4 4 },
5 5 "nbformat": 3,
6 6 "nbformat_minor": 0,
7 7 "worksheets": [
8 8 {
9 9 "cells": [
10 10 {
11 11 "cell_type": "raw",
12 12 "metadata": {
13 "raw_format": "html"
13 "raw_mimetype": "text/html"
14 14 },
15 15 "source": [
16 16 "<b>raw html</b>"
17 17 ]
18 18 },
19 19 {
20 20 "cell_type": "raw",
21 21 "metadata": {
22 "raw_format": "markdown"
22 "raw_mimetype": "text/markdown"
23 23 },
24 24 "source": [
25 25 "* raw markdown\n",
26 26 "* bullet\n",
27 27 "* list"
28 28 ]
29 29 },
30 30 {
31 31 "cell_type": "raw",
32 32 "metadata": {
33 "raw_format": "rst"
33 "raw_mimetype": "text/restructuredtext"
34 34 },
35 35 "source": [
36 36 "``raw rst``\n",
37 37 "\n",
38 38 ".. sourcecode:: python\n",
39 39 "\n",
40 40 " def foo(): pass\n"
41 41 ]
42 42 },
43 43 {
44 44 "cell_type": "raw",
45 45 "metadata": {
46 "raw_format": "python"
46 "raw_mimetype": "application/x-python"
47 47 },
48 48 "source": [
49 49 "def bar():\n",
50 50 " \"\"\"raw python\"\"\"\n",
51 51 " pass"
52 52 ]
53 53 },
54 54 {
55 55 "cell_type": "raw",
56 56 "metadata": {
57 "raw_format": "latex"
57 "raw_mimetype": "text/latex"
58 58 },
59 59 "source": [
60 60 "\\LaTeX\n",
61 61 "% raw latex"
62 62 ]
63 63 },
64 64 {
65 65 "cell_type": "raw",
66 66 "metadata": {},
67 67 "source": [
68 "# no raw_format metadata, should be included by default"
68 "# no raw_mimetype metadata, should be included by default"
69 69 ]
70 70 },
71 71 {
72 72 "cell_type": "raw",
73 73 "metadata": {
74 "raw_format": "doesnotexist"
74 "raw_mimetype": "doesnotexist"
75 75 },
76 76 "source": [
77 77 "garbage format defined, should never be included"
78 78 ]
79 79 }
80 80 ],
81 81 "metadata": {}
82 82 }
83 83 ]
84 84 } No newline at end of file
@@ -1,98 +1,98 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 ((=
6 6
7 7 DO NOT USE THIS AS A BASE,
8 8 IF YOU ARE COPY AND PASTING THIS FILE
9 9 YOU ARE PROBABLY DOING THINGS INCORRECTLY.
10 10
11 11 Null template, does nothing except defining a basic structure
12 12 To layout the different blocks of a notebook.
13 13
14 14 Subtemplates can override blocks to define their custom representation.
15 15
16 16 If one of the block you do overwrite is not a leave block, consider
17 17 calling super.
18 18
19 19 ((*- block nonLeaveBlock -*))
20 20 #add stuff at beginning
21 21 ((( super() )))
22 22 #add stuff at end
23 23 ((*- endblock nonLeaveBlock -*))
24 24
25 25 consider calling super even if it is a leave block, we might insert more blocks later.
26 26
27 27 =))
28 28 ((*- block header -*))
29 29 ((*- endblock header -*))
30 30 ((*- block body -*))
31 31 ((*- for worksheet in nb.worksheets -*))
32 32 ((*- for cell in worksheet.cells -*))
33 33 ((*- block any_cell scoped -*))
34 34 ((*- if cell.cell_type in ['code'] -*))
35 35 ((*- block codecell scoped -*))
36 36 ((*- block input_group -*))
37 37 ((*- block in_prompt -*))((*- endblock in_prompt -*))
38 38 ((*- block input -*))((*- endblock input -*))
39 39 ((*- endblock input_group -*))
40 40 ((*- if cell.outputs -*))
41 41 ((*- block output_group -*))
42 42 ((*- block output_prompt -*))((*- endblock output_prompt -*))
43 43 ((*- block outputs scoped -*))
44 44 ((*- for output in cell.outputs -*))
45 45 ((*- block output scoped -*))
46 46 ((*- if output.output_type in ['pyout'] -*))
47 47 ((*- block pyout scoped -*))((*- endblock pyout -*))
48 48 ((*- elif output.output_type in ['stream'] -*))
49 49 ((*- block stream scoped -*))
50 50 ((*- if output.stream in ['stdout'] -*))
51 51 ((*- block stream_stdout scoped -*))
52 52 ((*- endblock stream_stdout -*))
53 53 ((*- elif output.stream in ['stderr'] -*))
54 54 ((*- block stream_stderr scoped -*))
55 55 ((*- endblock stream_stderr -*))
56 56 ((*- endif -*))
57 57 ((*- endblock stream -*))
58 58 ((*- elif output.output_type in ['display_data'] -*))
59 59 ((*- block display_data scoped -*))
60 60 ((*- block data_priority scoped -*))
61 61 ((*- endblock data_priority -*))
62 62 ((*- endblock display_data -*))
63 63 ((*- elif output.output_type in ['pyerr'] -*))
64 64 ((*- block pyerr scoped -*))
65 65 ((*- for line in output.traceback -*))
66 66 ((*- block traceback_line scoped -*))((*- endblock traceback_line -*))
67 67 ((*- endfor -*))
68 68 ((*- endblock pyerr -*))
69 69 ((*- endif -*))
70 70 ((*- endblock output -*))
71 71 ((*- endfor -*))
72 72 ((*- endblock outputs -*))
73 73 ((*- endblock output_group -*))
74 74 ((*- endif -*))
75 75 ((*- endblock codecell -*))
76 76 ((*- elif cell.cell_type in ['markdown'] -*))
77 77 ((*- block markdowncell scoped-*))
78 78 ((*- endblock markdowncell -*))
79 79 ((*- elif cell.cell_type in ['heading'] -*))
80 80 ((*- block headingcell scoped-*))
81 81 ((*- endblock headingcell -*))
82 82 ((*- elif cell.cell_type in ['raw'] -*))
83 83 ((*- block rawcell scoped -*))
84 ((* if cell.metadata.get('raw_format', resources.get('raw_format')) == resources.get('raw_format') *))
84 ((* if cell.metadata.get('raw_mimetype', resources.get('raw_mimetype')) == resources.get('raw_mimetype') *))
85 85 ((( cell.source )))
86 86 ((* endif *))
87 87 ((*- endblock rawcell -*))
88 88 ((*- else -*))
89 89 ((*- block unknowncell scoped-*))
90 90 ((*- endblock unknowncell -*))
91 91 ((*- endif -*))
92 92 ((*- endblock any_cell -*))
93 93 ((*- endfor -*))
94 94 ((*- endfor -*))
95 95 ((*- endblock body -*))
96 96
97 97 ((*- block footer -*))
98 98 ((*- endblock footer -*))
@@ -1,94 +1,94 b''
1 1 {#
2 2
3 3 DO NOT USE THIS AS A BASE,
4 4 IF YOU ARE COPY AND PASTING THIS FILE
5 5 YOU ARE PROBABLY DOING THINGS INCORRECTLY.
6 6
7 7 Null template, does nothing except defining a basic structure
8 8 To layout the different blocks of a notebook.
9 9
10 10 Subtemplates can override blocks to define their custom representation.
11 11
12 12 If one of the block you do overwrite is not a leave block, consider
13 13 calling super.
14 14
15 15 {%- block nonLeaveBlock -%}
16 16 #add stuff at beginning
17 17 {{ super() }}
18 18 #add stuff at end
19 19 {%- endblock nonLeaveBlock -%}
20 20
21 21 consider calling super even if it is a leave block, we might insert more blocks later.
22 22
23 23 #}
24 24 {%- block header -%}
25 25 {%- endblock header -%}
26 26 {%- block body -%}
27 27 {%- for worksheet in nb.worksheets -%}
28 28 {%- for cell in worksheet.cells -%}
29 29 {%- block any_cell scoped -%}
30 30 {%- if cell.cell_type in ['code'] -%}
31 31 {%- block codecell scoped -%}
32 32 {%- block input_group -%}
33 33 {%- block in_prompt -%}{%- endblock in_prompt -%}
34 34 {%- block input -%}{%- endblock input -%}
35 35 {%- endblock input_group -%}
36 36 {%- if cell.outputs -%}
37 37 {%- block output_group -%}
38 38 {%- block output_prompt -%}{%- endblock output_prompt -%}
39 39 {%- block outputs scoped -%}
40 40 {%- for output in cell.outputs -%}
41 41 {%- block output scoped -%}
42 42 {%- if output.output_type in ['pyout'] -%}
43 43 {%- block pyout scoped -%}{%- endblock pyout -%}
44 44 {%- elif output.output_type in ['stream'] -%}
45 45 {%- block stream scoped -%}
46 46 {%- if output.stream in ['stdout'] -%}
47 47 {%- block stream_stdout scoped -%}
48 48 {%- endblock stream_stdout -%}
49 49 {%- elif output.stream in ['stderr'] -%}
50 50 {%- block stream_stderr scoped -%}
51 51 {%- endblock stream_stderr -%}
52 52 {%- endif -%}
53 53 {%- endblock stream -%}
54 54 {%- elif output.output_type in ['display_data'] -%}
55 55 {%- block display_data scoped -%}
56 56 {%- block data_priority scoped -%}
57 57 {%- endblock data_priority -%}
58 58 {%- endblock display_data -%}
59 59 {%- elif output.output_type in ['pyerr'] -%}
60 60 {%- block pyerr scoped -%}
61 61 {%- for line in output.traceback -%}
62 62 {%- block traceback_line scoped -%}{%- endblock traceback_line -%}
63 63 {%- endfor -%}
64 64 {%- endblock pyerr -%}
65 65 {%- endif -%}
66 66 {%- endblock output -%}
67 67 {%- endfor -%}
68 68 {%- endblock outputs -%}
69 69 {%- endblock output_group -%}
70 70 {%- endif -%}
71 71 {%- endblock codecell -%}
72 72 {%- elif cell.cell_type in ['markdown'] -%}
73 73 {%- block markdowncell scoped-%}
74 74 {%- endblock markdowncell -%}
75 75 {%- elif cell.cell_type in ['heading'] -%}
76 76 {%- block headingcell scoped-%}
77 77 {%- endblock headingcell -%}
78 78 {%- elif cell.cell_type in ['raw'] -%}
79 79 {%- block rawcell scoped -%}
80 {% if cell.metadata.get('raw_format', resources.get('raw_format', '')).lower() in resources.get('raw_formats', ['']) %}
80 {% if cell.metadata.get('raw_mimetype', resources.get('raw_mimetype', '')).lower() in resources.get('raw_mimetypes', ['']) %}
81 81 {{ cell.source }}
82 82 {% endif %}
83 83 {%- endblock rawcell -%}
84 84 {%- else -%}
85 85 {%- block unknowncell scoped-%}
86 86 {%- endblock unknowncell -%}
87 87 {%- endif -%}
88 88 {%- endblock any_cell -%}
89 89 {%- endfor -%}
90 90 {%- endfor -%}
91 91 {%- endblock body -%}
92 92
93 93 {%- block footer -%}
94 94 {%- endblock footer -%}
General Comments 0
You need to be logged in to leave comments. Login now