Show More
@@ -35,8 +35,6 b" def rst_directive(directive, text=''):" | |||
|
35 | 35 | return out |
|
36 | 36 | |
|
37 | 37 | # Converters for parts of a cell. |
|
38 | figures_counter = 1 | |
|
39 | ||
|
40 | 38 | |
|
41 | 39 | class ConversionException(Exception): |
|
42 | 40 | pass |
@@ -47,6 +45,7 b' class Converter(object):' | |||
|
47 | 45 | |
|
48 | 46 | def __init__(self, fname): |
|
49 | 47 | self.fname = fname |
|
48 | self.dirpath = os.path.dirname(fname) | |
|
50 | 49 | |
|
51 | 50 | @property |
|
52 | 51 | def extension(self): |
@@ -108,6 +107,7 b' class Converter(object):' | |||
|
108 | 107 | |
|
109 | 108 | class ConverterRST(Converter): |
|
110 | 109 | extension = 'rst' |
|
110 | figures_counter = 0 | |
|
111 | 111 | |
|
112 | 112 | def render_heading(self, cell): |
|
113 | 113 | """convert a heading cell to rst |
@@ -131,7 +131,7 b' class ConverterRST(Converter):' | |||
|
131 | 131 | for output in cell.outputs: |
|
132 | 132 | conv_fn = self.dispatch(output.output_type) |
|
133 | 133 | lines.extend(conv_fn(output)) |
|
134 | ||
|
134 | ||
|
135 | 135 | return lines |
|
136 | 136 | |
|
137 | 137 | def render_markdown(self, cell): |
@@ -161,16 +161,15 b' class ConverterRST(Converter):' | |||
|
161 | 161 | |
|
162 | 162 | Returns list. |
|
163 | 163 | """ |
|
164 | global figures_counter | |
|
165 | ||
|
166 | 164 | lines = [] |
|
167 | 165 | |
|
168 | 166 | if 'png' in output: |
|
169 | fname = 'nb_figure_%s.png' % figures_counter | |
|
170 | with open(fname, 'w') as f: | |
|
167 | fname = 'nb_figure_%s.png' % self.figures_counter | |
|
168 | fullname = os.path.join(self.dirpath, fname) | |
|
169 | with open(fullname, 'w') as f: | |
|
171 | 170 | f.write(output.png.decode('base64')) |
|
172 | 171 | |
|
173 | figures_counter += 1 | |
|
172 | self.figures_counter += 1 | |
|
174 | 173 | lines.append('.. image:: %s' % fname) |
|
175 | 174 | lines.append('') |
|
176 | 175 |
General Comments 0
You need to be logged in to leave comments.
Login now