Show More
@@ -39,8 +39,8 b' class HTMLExporter(TemplateExporter):' | |||||
39 | default_template = Unicode('full', config=True, help="""Flavor of the data |
|
39 | default_template = Unicode('full', config=True, help="""Flavor of the data | |
40 | format to use. I.E. 'full' or 'basic'""") |
|
40 | format to use. I.E. 'full' or 'basic'""") | |
41 |
|
41 | |||
42 |
def _raw_ |
|
42 | def _raw_mimetype_default(self): | |
43 | return 'html' |
|
43 | return 'text/html' | |
44 |
|
44 | |||
45 | @property |
|
45 | @property | |
46 | def default_config(self): |
|
46 | def default_config(self): |
@@ -63,8 +63,8 b' class LatexExporter(TemplateExporter):' | |||||
63 | #Extension that the template files use. |
|
63 | #Extension that the template files use. | |
64 | template_extension = Unicode(".tplx", config=True) |
|
64 | template_extension = Unicode(".tplx", config=True) | |
65 |
|
65 | |||
66 |
def _raw_ |
|
66 | def _raw_mimetype_default(self): | |
67 | return 'latex' |
|
67 | return 'text/latex' | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | @property |
|
70 | @property |
@@ -30,11 +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_ |
|
33 | def _raw_mimetype_default(self): | |
34 | return 'markdown' |
|
34 | return 'text/markdown' | |
35 |
|
35 | |||
36 |
def _raw_ |
|
36 | def _raw_mimetypes_default(self): | |
37 |
return ['md', ' |
|
37 | return ['text/markdown', 'text/html'] | |
38 |
|
38 | |||
39 | @property |
|
39 | @property | |
40 | def default_config(self): |
|
40 | def default_config(self): |
@@ -29,9 +29,6 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_ |
|
32 | def _raw_mimetype_default(self): | |
33 | return 'python' |
|
33 | return 'application/x-python' | |
34 |
|
||||
35 | def _raw_formats_default(self): |
|
|||
36 | return ['py', 'python'] |
|
|||
37 |
|
34 |
@@ -30,12 +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_ |
|
33 | def _raw_mimetype_default(self): | |
34 | return 'rst' |
|
34 | return 'text/restructuredtext' | |
35 |
|
35 | |||
36 | def _raw_formats_default(self): |
|
|||
37 | return ['rst', 'restructuredtext'] |
|
|||
38 |
|
||||
39 | @property |
|
36 | @property | |
40 | def default_config(self): |
|
37 | def default_config(self): | |
41 | c = Config({'ExtractOutputPreprocessor':{'enabled':True}}) |
|
38 | c = Config({'ExtractOutputPreprocessor':{'enabled':True}}) |
@@ -126,12 +126,12 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_ |
|
129 | raw_mimetype = Unicode('') | |
130 |
raw_ |
|
130 | raw_mimetypes = List(config=True, | |
131 | help="""formats of raw cells to be included in this Exporter's output.""" |
|
131 | help="""formats of raw cells to be included in this Exporter's output.""" | |
132 | ) |
|
132 | ) | |
133 |
def _raw_ |
|
133 | def _raw_mimetypes_default(self): | |
134 |
return [self.raw_ |
|
134 | return [self.raw_mimetype] | |
135 |
|
135 | |||
136 |
|
136 | |||
137 | def __init__(self, config=None, extra_loaders=None, **kw): |
|
137 | def __init__(self, config=None, extra_loaders=None, **kw): | |
@@ -209,8 +209,8 b' class TemplateExporter(Exporter):' | |||||
209 | preprocessors and filters. |
|
209 | preprocessors and filters. | |
210 | """ |
|
210 | """ | |
211 | nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw) |
|
211 | nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw) | |
212 |
resources.setdefault('raw_ |
|
212 | resources.setdefault('raw_mimetype', self.raw_mimetype) | |
213 |
resources.setdefault('raw_ |
|
213 | resources.setdefault('raw_mimetypes', self.raw_mimetypes) | |
214 |
|
214 | |||
215 | self._load_template() |
|
215 | self._load_template() | |
216 |
|
216 |
@@ -22,7 +22,13 b' from ...tests.base import TestsBase' | |||||
22 | # Class |
|
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 | class ExportersTestsBase(TestsBase): |
|
33 | class ExportersTestsBase(TestsBase): | |
28 | """Contains base test functions for exporters""" |
|
34 | """Contains base test functions for exporters""" | |
@@ -35,14 +41,14 b' class ExportersTestsBase(TestsBase):' | |||||
35 |
|
41 | |||
36 | @onlyif_cmds_exist('pandoc') |
|
42 | @onlyif_cmds_exist('pandoc') | |
37 | def test_raw_cell_inclusion(self): |
|
43 | def test_raw_cell_inclusion(self): | |
38 |
"""test raw cell inclusion based on raw_ |
|
44 | """test raw cell inclusion based on raw_mimetype metadata""" | |
39 | if self.should_include_raw is None: |
|
45 | if self.should_include_raw is None: | |
40 | return |
|
46 | return | |
41 | exporter = self.exporter_class() |
|
47 | exporter = self.exporter_class() | |
42 | (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb')) |
|
48 | (output, resources) = exporter.from_filename(self._get_notebook('rawtest.ipynb')) | |
43 | for inc in self.should_include_raw: |
|
49 | for inc in self.should_include_raw: | |
44 | self.assertIn('raw %s' % inc, output, "should include %s" % inc) |
|
50 | self.assertIn('raw %s' % inc, output, "should include %s" % inc) | |
45 |
self.assertIn('no raw_ |
|
51 | self.assertIn('no raw_mimetype metadata', output) | |
46 |
for exc in all_raw_ |
|
52 | for exc in all_raw_mimetypes.difference(self.should_include_raw): | |
47 | self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc) |
|
53 | self.assertNotIn('raw %s' % exc, output, "should exclude %s" % exc) | |
48 | self.assertNotIn('never be included', output) |
|
54 | self.assertNotIn('never be included', output) |
@@ -10,7 +10,7 b'' | |||||
10 | { |
|
10 | { | |
11 | "cell_type": "raw", |
|
11 | "cell_type": "raw", | |
12 | "metadata": { |
|
12 | "metadata": { | |
13 |
"raw_ |
|
13 | "raw_mimetype": "text/html" | |
14 | }, |
|
14 | }, | |
15 | "source": [ |
|
15 | "source": [ | |
16 | "<b>raw html</b>" |
|
16 | "<b>raw html</b>" | |
@@ -19,7 +19,7 b'' | |||||
19 | { |
|
19 | { | |
20 | "cell_type": "raw", |
|
20 | "cell_type": "raw", | |
21 | "metadata": { |
|
21 | "metadata": { | |
22 |
"raw_ |
|
22 | "raw_mimetype": "text/markdown" | |
23 | }, |
|
23 | }, | |
24 | "source": [ |
|
24 | "source": [ | |
25 | "* raw markdown\n", |
|
25 | "* raw markdown\n", | |
@@ -30,7 +30,7 b'' | |||||
30 | { |
|
30 | { | |
31 | "cell_type": "raw", |
|
31 | "cell_type": "raw", | |
32 | "metadata": { |
|
32 | "metadata": { | |
33 |
"raw_ |
|
33 | "raw_mimetype": "text/restructuredtext" | |
34 | }, |
|
34 | }, | |
35 | "source": [ |
|
35 | "source": [ | |
36 | "``raw rst``\n", |
|
36 | "``raw rst``\n", | |
@@ -43,7 +43,7 b'' | |||||
43 | { |
|
43 | { | |
44 | "cell_type": "raw", |
|
44 | "cell_type": "raw", | |
45 | "metadata": { |
|
45 | "metadata": { | |
46 |
"raw_ |
|
46 | "raw_mimetype": "application/x-python" | |
47 | }, |
|
47 | }, | |
48 | "source": [ |
|
48 | "source": [ | |
49 | "def bar():\n", |
|
49 | "def bar():\n", | |
@@ -54,7 +54,7 b'' | |||||
54 | { |
|
54 | { | |
55 | "cell_type": "raw", |
|
55 | "cell_type": "raw", | |
56 | "metadata": { |
|
56 | "metadata": { | |
57 |
"raw_ |
|
57 | "raw_mimetype": "text/latex" | |
58 | }, |
|
58 | }, | |
59 | "source": [ |
|
59 | "source": [ | |
60 | "\\LaTeX\n", |
|
60 | "\\LaTeX\n", | |
@@ -65,13 +65,13 b'' | |||||
65 | "cell_type": "raw", |
|
65 | "cell_type": "raw", | |
66 | "metadata": {}, |
|
66 | "metadata": {}, | |
67 | "source": [ |
|
67 | "source": [ | |
68 |
"# no raw_ |
|
68 | "# no raw_mimetype metadata, should be included by default" | |
69 | ] |
|
69 | ] | |
70 | }, |
|
70 | }, | |
71 | { |
|
71 | { | |
72 | "cell_type": "raw", |
|
72 | "cell_type": "raw", | |
73 | "metadata": { |
|
73 | "metadata": { | |
74 |
"raw_ |
|
74 | "raw_mimetype": "doesnotexist" | |
75 | }, |
|
75 | }, | |
76 | "source": [ |
|
76 | "source": [ | |
77 | "garbage format defined, should never be included" |
|
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 | ((*- 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_ |
|
84 | ((* if cell.metadata.get('raw_mimetype', resources.get('raw_mimetype')) == resources.get('raw_mimetype') *)) | |
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_ |
|
80 | {% if cell.metadata.get('raw_mimetype', resources.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