diff --git a/IPython/nbconvert/preprocessors/convertfigures.py b/IPython/nbconvert/preprocessors/convertfigures.py index d0dd3dc..3fafe73 100644 --- a/IPython/nbconvert/preprocessors/convertfigures.py +++ b/IPython/nbconvert/preprocessors/convertfigures.py @@ -47,18 +47,12 @@ class ConvertFiguresPreprocessor(Preprocessor): """ # Loop through all of the datatypes of the outputs in the cell. - for index, cell_out in enumerate(cell.get('outputs', [])): - for data_type, data in list(cell_out.items()): - # this must run *before* extract outputs, - # so figure_name and filename do not exist - self._convert_figure(cell_out, resources, data_type, data) - return cell, resources + for output in cell.get('outputs', []): + if output.output_type in {'execute_result', 'display_data'} \ + and self.from_format in output.data \ + and self.to_format not in output.data: + output.data[self.to_format] = self.convert_figure( + self.from_format, output.data[self.from_format]) - def _convert_figure(self, cell_out, resources, data_type, data): - """ - Convert a figure and output the results to the cell output - """ - if not self.to_format in cell_out and data_type == self.from_format: - data = self.convert_figure(data_type, data) - cell_out[self.to_format] = data + return cell, resources diff --git a/IPython/nbconvert/preprocessors/svg2pdf.py b/IPython/nbconvert/preprocessors/svg2pdf.py index 09c7585..aa1786c 100644 --- a/IPython/nbconvert/preprocessors/svg2pdf.py +++ b/IPython/nbconvert/preprocessors/svg2pdf.py @@ -61,7 +61,7 @@ class SVG2PDFPreprocessor(ConvertFiguresPreprocessor): with TemporaryDirectory() as tmpdir: #Write fig to temp file - input_filename = os.path.join(tmpdir, 'figure.' + data_format) + input_filename = os.path.join(tmpdir, 'figure.svg') # SVG data is unicode text with io.open(input_filename, 'w', encoding='utf8') as f: f.write(data) diff --git a/IPython/nbconvert/preprocessors/tests/test_svg2pdf.py b/IPython/nbconvert/preprocessors/tests/test_svg2pdf.py index e69e926..6b672f6 100644 --- a/IPython/nbconvert/preprocessors/tests/test_svg2pdf.py +++ b/IPython/nbconvert/preprocessors/tests/test_svg2pdf.py @@ -42,10 +42,9 @@ class Testsvg2pdf(PreprocessorTestsBase): """Build a reveal slides notebook in memory for use with tests. Overrides base in PreprocessorTestsBase""" - outputs = [nbformat.new_output(output_type="image/svg+xml", output_svg=self.simple_svg)] - - slide_metadata = {'slideshow' : {'slide_type': 'slide'}} - subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}} + outputs = [nbformat.new_output(output_type='display_data', + data={'image/svg+xml':self.simple_svg}) + ] cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)] @@ -71,4 +70,4 @@ class Testsvg2pdf(PreprocessorTestsBase): res = self.build_resources() preprocessor = self.build_preprocessor() nb, res = preprocessor(nb, res) - self.assertIn('application/pdf', nb.cells[0].outputs[0]) + self.assertIn('application/pdf', nb.cells[0].outputs[0].data)