Show More
@@ -7,6 +7,7 b' import io' | |||||
7 | import logging |
|
7 | import logging | |
8 | import os |
|
8 | import os | |
9 | import pprint |
|
9 | import pprint | |
|
10 | import re | |||
10 | from types import FunctionType |
|
11 | from types import FunctionType | |
11 |
|
12 | |||
12 | # From IPython |
|
13 | # From IPython | |
@@ -14,6 +15,11 b' from IPython.nbformat import current as nbformat' | |||||
14 |
|
15 | |||
15 | # local |
|
16 | # local | |
16 |
|
17 | |||
|
18 | def clean_filename(filename): | |||
|
19 | """Remove unusual characters from filename, so it works with LaTeX""" | |||
|
20 | filename = re.sub(r'[^a-zA-Z0-9_]', '_', filename) | |||
|
21 | return filename | |||
|
22 | ||||
17 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
18 | # Class declarations |
|
24 | # Class declarations | |
19 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
@@ -68,7 +74,7 b' class Converter(object):' | |||||
68 | self.infile = infile |
|
74 | self.infile = infile | |
69 | self.infile_dir, infile_root = os.path.split(infile) |
|
75 | self.infile_dir, infile_root = os.path.split(infile) | |
70 | infile_root = os.path.splitext(infile_root)[0] |
|
76 | infile_root = os.path.splitext(infile_root)[0] | |
71 | files_dir = os.path.join(self.infile_dir, infile_root + '_files') |
|
77 | files_dir = os.path.join(self.infile_dir, clean_filename(infile_root) + '_files') | |
72 | if not os.path.isdir(files_dir): |
|
78 | if not os.path.isdir(files_dir): | |
73 | os.mkdir(files_dir) |
|
79 | os.mkdir(files_dir) | |
74 | self.infile_root = infile_root |
|
80 | self.infile_root = infile_root | |
@@ -168,7 +174,7 b' class Converter(object):' | |||||
168 |
|
174 | |||
169 | Returns a path relative to the input file. |
|
175 | Returns a path relative to the input file. | |
170 | """ |
|
176 | """ | |
171 | figname = '%s_fig_%02i.%s' % (self.infile_root, |
|
177 | figname = '%s_fig_%02i.%s' % (clean_filename(self.infile_root), | |
172 | self.figures_counter, fmt) |
|
178 | self.figures_counter, fmt) | |
173 | self.figures_counter += 1 |
|
179 | self.figures_counter += 1 | |
174 | fullname = os.path.join(self.files_dir, figname) |
|
180 | fullname = os.path.join(self.files_dir, figname) |
General Comments 0
You need to be logged in to leave comments.
Login now