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