##// END OF EJS Templates
propagate raw_mimetype to nbconvert
MinRK -
Show More
@@ -39,8 +39,8 b' class HTMLExporter(TemplateExporter):'
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):
@@ -63,8 +63,8 b' class LatexExporter(TemplateExporter):'
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
@@ -30,11 +30,11 b' class MarkdownExporter(TemplateExporter):'
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):
@@ -29,9 +29,6 b' class PythonExporter(TemplateExporter):'
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
@@ -30,12 +30,9 b' class RSTExporter(TemplateExporter):'
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}})
@@ -126,12 +126,12 b' class TemplateExporter(Exporter):'
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):
@@ -209,8 +209,8 b' class TemplateExporter(Exporter):'
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
@@ -22,7 +22,13 b' from ...tests.base import TestsBase'
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"""
@@ -35,14 +41,14 b' class ExportersTestsBase(TestsBase):'
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)
@@ -10,7 +10,7 b''
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>"
@@ -19,7 +19,7 b''
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",
@@ -30,7 +30,7 b''
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",
@@ -43,7 +43,7 b''
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",
@@ -54,7 +54,7 b''
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",
@@ -65,13 +65,13 b''
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"
@@ -81,7 +81,7 b' consider calling super even if it is a leave block, we might insert more blocks '
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 -*))
@@ -77,7 +77,7 b' consider calling super even if it is a leave block, we might insert more blocks '
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 -%}
General Comments 0
You need to be logged in to leave comments. Login now