Show More
@@ -47,18 +47,12 b' class ConvertFiguresPreprocessor(Preprocessor):' | |||
|
47 | 47 | """ |
|
48 | 48 | |
|
49 | 49 | # Loop through all of the datatypes of the outputs in the cell. |
|
50 |
for |
|
|
51 | for data_type, data in list(cell_out.items()): | |
|
52 | # this must run *before* extract outputs, | |
|
53 | # so figure_name and filename do not exist | |
|
54 | self._convert_figure(cell_out, resources, data_type, data) | |
|
55 | return cell, resources | |
|
50 | for output in cell.get('outputs', []): | |
|
51 | if output.output_type in {'execute_result', 'display_data'} \ | |
|
52 | and self.from_format in output.data \ | |
|
53 | and self.to_format not in output.data: | |
|
56 | 54 | |
|
55 | output.data[self.to_format] = self.convert_figure( | |
|
56 | self.from_format, output.data[self.from_format]) | |
|
57 | 57 | |
|
58 | def _convert_figure(self, cell_out, resources, data_type, data): | |
|
59 | """ | |
|
60 | Convert a figure and output the results to the cell output | |
|
61 | """ | |
|
62 | if not self.to_format in cell_out and data_type == self.from_format: | |
|
63 | data = self.convert_figure(data_type, data) | |
|
64 | cell_out[self.to_format] = data | |
|
58 | return cell, resources |
@@ -61,7 +61,7 b' class SVG2PDFPreprocessor(ConvertFiguresPreprocessor):' | |||
|
61 | 61 | with TemporaryDirectory() as tmpdir: |
|
62 | 62 | |
|
63 | 63 | #Write fig to temp file |
|
64 |
input_filename = os.path.join(tmpdir, 'figure.' |
|
|
64 | input_filename = os.path.join(tmpdir, 'figure.svg') | |
|
65 | 65 | # SVG data is unicode text |
|
66 | 66 | with io.open(input_filename, 'w', encoding='utf8') as f: |
|
67 | 67 | f.write(data) |
@@ -42,10 +42,9 b' class Testsvg2pdf(PreprocessorTestsBase):' | |||
|
42 | 42 | """Build a reveal slides notebook in memory for use with tests. |
|
43 | 43 | Overrides base in PreprocessorTestsBase""" |
|
44 | 44 | |
|
45 |
outputs = [nbformat.new_output(output_type= |
|
|
46 | ||
|
47 | slide_metadata = {'slideshow' : {'slide_type': 'slide'}} | |
|
48 | subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} | |
|
45 | outputs = [nbformat.new_output(output_type='display_data', | |
|
46 | data={'image/svg+xml':self.simple_svg}) | |
|
47 | ] | |
|
49 | 48 | |
|
50 | 49 | cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)] |
|
51 | 50 | |
@@ -71,4 +70,4 b' class Testsvg2pdf(PreprocessorTestsBase):' | |||
|
71 | 70 | res = self.build_resources() |
|
72 | 71 | preprocessor = self.build_preprocessor() |
|
73 | 72 | nb, res = preprocessor(nb, res) |
|
74 | self.assertIn('application/pdf', nb.cells[0].outputs[0]) | |
|
73 | self.assertIn('application/pdf', nb.cells[0].outputs[0].data) |
General Comments 0
You need to be logged in to leave comments.
Login now