Show More
@@ -188,6 +188,7 b' class NbConvertApp(BaseIPythonApplication):' | |||
|
188 | 188 | notebook_name = basename[:basename.rfind('.')] |
|
189 | 189 | resources = {} |
|
190 | 190 | resources['unique_key'] = notebook_name |
|
191 | resources['output_files_dir'] = '%s_files' % notebook_name | |
|
191 | 192 | |
|
192 | 193 | #Try to export |
|
193 | 194 | try: |
@@ -15,6 +15,7 b" notebook file. The extracted figures are returned in the 'resources' dictionary" | |||
|
15 | 15 | |
|
16 | 16 | import base64 |
|
17 | 17 | import sys |
|
18 | import os | |
|
18 | 19 | |
|
19 | 20 | from IPython.utils.traitlets import Unicode |
|
20 | 21 | from .base import Transformer |
@@ -50,8 +51,10 b' class ExtractFigureTransformer(Transformer):' | |||
|
50 | 51 | """ |
|
51 | 52 | |
|
52 | 53 | #Get the unique key from the resource dict if it exists. If it does not |
|
53 | #exist, use 'figure' as the default. | |
|
54 | #exist, use 'figure' as the default. Also, get files directory if it | |
|
55 | #has been specified | |
|
54 | 56 | unique_key = resources.get('unique_key', 'figure') |
|
57 | output_files_dir = resources.get('output_files_dir', None) | |
|
55 | 58 | |
|
56 | 59 | #Make sure figures key exists |
|
57 | 60 | if not 'figures' in resources: |
@@ -77,7 +80,7 b' class ExtractFigureTransformer(Transformer):' | |||
|
77 | 80 | data = data.encode("UTF-8") |
|
78 | 81 | |
|
79 | 82 | #Build a figure name |
|
80 |
fi |
|
|
83 | filename = self.figure_filename_template.format( | |
|
81 | 84 | unique_key=unique_key, |
|
82 | 85 | cell_index=cell_index, |
|
83 | 86 | index=index, |
@@ -87,10 +90,12 b' class ExtractFigureTransformer(Transformer):' | |||
|
87 | 90 | # cell.outputs[i].svg_filename ... etc (svg in example) |
|
88 | 91 | # Where |
|
89 | 92 | # cell.outputs[i].svg contains the data |
|
90 | out[out_type + '_filename'] = figure_name | |
|
93 | if output_files_dir is not None: | |
|
94 | filename = os.path.join(output_files_dir, filename) | |
|
95 | out[out_type + '_filename'] = filename | |
|
91 | 96 | |
|
92 | 97 | #In the resources, make the figure available via |
|
93 | 98 | # resources['figures']['filename'] = data |
|
94 |
resources['figures'][fi |
|
|
99 | resources['figures'][filename] = data | |
|
95 | 100 | |
|
96 | 101 | return cell, resources |
General Comments 0
You need to be logged in to leave comments.
Login now