From 20af107613f346b5e6dd7fdd55ea592a24088211 2014-11-24 20:11:03 From: Thomas Kluyver Date: 2014-11-24 20:11:03 Subject: [PATCH] Fix svg2pdf filter --- 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)