##// END OF EJS Templates
Condense raw_mimetype and mime_type traitlets into output_mimetype
Thomas Kluyver -
Show More
@@ -36,8 +36,9 b' class NbconvertFileHandler(IPythonHandler):'
36 'attachment; filename="%s"' % filename)
36 'attachment; filename="%s"' % filename)
37
37
38 # MIME type
38 # MIME type
39 if exporter.mime_type:
39 if exporter.output_mimetype:
40 self.set_header('Content-Type', '%s; charset=utf-8' % exporter.mime_type)
40 self.set_header('Content-Type',
41 '%s; charset=utf-8' % exporter.output_mimetype)
41
42
42 output, resources = exporter.from_filename(os_path)
43 output, resources = exporter.from_filename(os_path)
43
44
@@ -57,8 +58,9 b' class NbconvertPostHandler(IPythonHandler):'
57 nbnode = to_notebook_json(model['content'])
58 nbnode = to_notebook_json(model['content'])
58
59
59 # MIME type
60 # MIME type
60 if exporter.mime_type:
61 if exporter.output_mimetype:
61 self.set_header('Content-Type', '%s; charset=utf-8' % exporter.mime_type)
62 self.set_header('Content-Type',
63 '%s; charset=utf-8' % exporter.output_mimetype)
62
64
63 output, resources = exporter.from_notebook_node(nbnode)
65 output, resources = exporter.from_notebook_node(nbnode)
64
66
@@ -22,7 +22,7 b''
22 ["reST", "text/restructuredtext"],
22 ["reST", "text/restructuredtext"],
23 ["HTML", "text/html"],
23 ["HTML", "text/html"],
24 ["Markdown", "text/markdown"],
24 ["Markdown", "text/markdown"],
25 ["Python", "application/x-python"],
25 ["Python", "text/x-python"],
26 ["Custom", "dialog"],
26 ["Custom", "dialog"],
27
27
28 ],
28 ],
@@ -87,4 +87,4 b''
87 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
87 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
88 console.log('Raw Cell Format toolbar preset loaded.');
88 console.log('Raw Cell Format toolbar preset loaded.');
89
89
90 }(IPython)); No newline at end of file
90 }(IPython));
@@ -53,7 +53,7 b' class Exporter(LoggingConfigurable):'
53 help="Extension of the file that should be written to disk"
53 help="Extension of the file that should be written to disk"
54 )
54 )
55
55
56 mime_type = Unicode('', config=True,
56 output_mimetype = Unicode('', config=True,
57 help="MIME type of the result file, for HTTP response headers."
57 help="MIME type of the result file, for HTTP response headers."
58 )
58 )
59
59
@@ -43,7 +43,7 b' class HTMLExporter(TemplateExporter):'
43 default_template = Unicode('full', config=True, help="""Flavor of the data
43 default_template = Unicode('full', config=True, help="""Flavor of the data
44 format to use. I.E. 'full' or 'basic'""")
44 format to use. I.E. 'full' or 'basic'""")
45
45
46 def _raw_mimetype_default(self):
46 def _output_mimetype_default(self):
47 return 'text/html'
47 return 'text/html'
48
48
49 @property
49 @property
@@ -40,10 +40,6 b' class LatexExporter(TemplateExporter):'
40 'tex', config=True,
40 'tex', config=True,
41 help="Extension of the file that should be written to disk")
41 help="Extension of the file that should be written to disk")
42
42
43 mime_type = Unicode('application/x-tex', config=True,
44 help="MIME type of the result file, for HTTP response headers."
45 )
46
47 default_template = Unicode('article', config=True, help="""Template of the
43 default_template = Unicode('article', config=True, help="""Template of the
48 data format to use. I.E. 'article' or 'report'""")
44 data format to use. I.E. 'article' or 'report'""")
49
45
@@ -67,7 +63,7 b' class LatexExporter(TemplateExporter):'
67 #Extension that the template files use.
63 #Extension that the template files use.
68 template_extension = Unicode(".tplx", config=True)
64 template_extension = Unicode(".tplx", config=True)
69
65
70 def _raw_mimetype_default(self):
66 def _output_mimetype_default(self):
71 return 'text/latex'
67 return 'text/latex'
72
68
73
69
@@ -30,15 +30,11 b' class MarkdownExporter(TemplateExporter):'
30 'md', config=True,
30 'md', config=True,
31 help="Extension of the file that should be written to disk")
31 help="Extension of the file that should be written to disk")
32
32
33 def _raw_mimetype_default(self):
33 def _output_mimetype_default(self):
34 return 'text/markdown'
34 return 'text/markdown'
35
35
36 def _raw_mimetypes_default(self):
36 def _raw_mimetypes_default(self):
37 return ['text/markdown', 'text/html']
37 return ['text/markdown', 'text/html', '']
38
39 mime_type = Unicode('text/x-markdown', config=True,
40 help="MIME type of the result file, for HTTP response headers."
41 )
42
38
43 @property
39 @property
44 def default_config(self):
40 def default_config(self):
@@ -29,9 +29,5 b' class PythonExporter(TemplateExporter):'
29 'py', config=True,
29 'py', config=True,
30 help="Extension of the file that should be written to disk")
30 help="Extension of the file that should be written to disk")
31
31
32 def _raw_mimetype_default(self):
32 def _output_mimetype_default(self):
33 return 'application/x-python'
33 return 'text/x-python'
34
35 mime_type = Unicode('text/x-python', config=True,
36 help="MIME type of the result file, for HTTP response headers."
37 )
@@ -30,13 +30,9 b' class RSTExporter(TemplateExporter):'
30 'rst', config=True,
30 'rst', config=True,
31 help="Extension of the file that should be written to disk")
31 help="Extension of the file that should be written to disk")
32
32
33 def _raw_mimetype_default(self):
33 def _output_mimetype_default(self):
34 return 'text/restructuredtext'
34 return 'text/restructuredtext'
35
35
36 mime_type = Unicode('text/x-rst', config=True,
37 help="MIME type of the result file, for HTTP response headers."
38 )
39
40 @property
36 @property
41 def default_config(self):
37 def default_config(self):
42 c = Config({'ExtractOutputPreprocessor':{'enabled':True}})
38 c = Config({'ExtractOutputPreprocessor':{'enabled':True}})
@@ -31,9 +31,8 b' class SlidesExporter(HTMLExporter):'
31 help="Extension of the file that should be written to disk"
31 help="Extension of the file that should be written to disk"
32 )
32 )
33
33
34 mime_type = Unicode('text/html', config=True,
34 def _output_mimetype_default(self):
35 help="MIME type of the result file, for HTTP response headers."
35 return 'text/html'
36 )
37
36
38 default_template = Unicode('reveal', config=True, help="""Template of the
37 default_template = Unicode('reveal', config=True, help="""Template of the
39 data format to use. I.E. 'reveal'""")
38 data format to use. I.E. 'reveal'""")
@@ -126,12 +126,13 b' class TemplateExporter(Exporter):'
126 help="""Dictionary of filters, by name and namespace, to add to the Jinja
126 help="""Dictionary of filters, by name and namespace, to add to the Jinja
127 environment.""")
127 environment.""")
128
128
129 raw_mimetype = Unicode('')
129 output_mimetype = Unicode('')
130
130 raw_mimetypes = List(config=True,
131 raw_mimetypes = List(config=True,
131 help="""formats of raw cells to be included in this Exporter's output."""
132 help="""formats of raw cells to be included in this Exporter's output."""
132 )
133 )
133 def _raw_mimetypes_default(self):
134 def _raw_mimetypes_default(self):
134 return [self.raw_mimetype]
135 return [self.output_mimetype, '']
135
136
136
137
137 def __init__(self, config=None, extra_loaders=None, **kw):
138 def __init__(self, config=None, extra_loaders=None, **kw):
@@ -209,7 +210,6 b' class TemplateExporter(Exporter):'
209 preprocessors and filters.
210 preprocessors and filters.
210 """
211 """
211 nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw)
212 nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw)
212 resources.setdefault('raw_mimetype', self.raw_mimetype)
213 resources.setdefault('raw_mimetypes', self.raw_mimetypes)
213 resources.setdefault('raw_mimetypes', self.raw_mimetypes)
214
214
215 self._load_template()
215 self._load_template()
@@ -23,7 +23,7 b' from ...tests.base import TestsBase'
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 all_raw_mimetypes = {
25 all_raw_mimetypes = {
26 'application/x-python',
26 'text/x-python',
27 'text/markdown',
27 'text/markdown',
28 'text/html',
28 'text/html',
29 'text/restructuredtext',
29 'text/restructuredtext',
@@ -43,7 +43,7 b''
43 {
43 {
44 "cell_type": "raw",
44 "cell_type": "raw",
45 "metadata": {
45 "metadata": {
46 "raw_mimetype": "application/x-python"
46 "raw_mimetype": "text/x-python"
47 },
47 },
48 "source": [
48 "source": [
49 "def bar():\n",
49 "def bar():\n",
@@ -81,4 +81,4 b''
81 "metadata": {}
81 "metadata": {}
82 }
82 }
83 ]
83 ]
84 } No newline at end of file
84 }
@@ -81,7 +81,7 b' consider calling super even if it is a leave block, we might insert more blocks '
81 ((*- endblock headingcell -*))
81 ((*- endblock headingcell -*))
82 ((*- elif cell.cell_type in ['raw'] -*))
82 ((*- elif cell.cell_type in ['raw'] -*))
83 ((*- block rawcell scoped -*))
83 ((*- block rawcell scoped -*))
84 ((* if cell.metadata.get('raw_mimetype', resources.get('raw_mimetype')) == resources.get('raw_mimetype') *))
84 ((* if cell.metadata.get('raw_mimetype', '').lower() in resources.get('raw_mimetypes', ['']) *))
85 ((( cell.source )))
85 ((( cell.source )))
86 ((* endif *))
86 ((* endif *))
87 ((*- endblock rawcell -*))
87 ((*- endblock rawcell -*))
@@ -77,7 +77,7 b' consider calling super even if it is a leave block, we might insert more blocks '
77 {%- endblock headingcell -%}
77 {%- endblock headingcell -%}
78 {%- elif cell.cell_type in ['raw'] -%}
78 {%- elif cell.cell_type in ['raw'] -%}
79 {%- block rawcell scoped -%}
79 {%- block rawcell scoped -%}
80 {% if cell.metadata.get('raw_mimetype', resources.get('raw_mimetype', '')).lower() in resources.get('raw_mimetypes', ['']) %}
80 {% if cell.metadata.get('raw_mimetype', '').lower() in resources.get('raw_mimetypes', ['']) %}
81 {{ cell.source }}
81 {{ cell.source }}
82 {% endif %}
82 {% endif %}
83 {%- endblock rawcell -%}
83 {%- endblock rawcell -%}
General Comments 0
You need to be logged in to leave comments. Login now