Show More
@@ -7,6 +7,7 b' import io' | |||
|
7 | 7 | import logging |
|
8 | 8 | import os |
|
9 | 9 | import pprint |
|
10 | import re | |
|
10 | 11 | from types import FunctionType |
|
11 | 12 | |
|
12 | 13 | # From IPython |
@@ -14,6 +15,11 b' from IPython.nbformat import current as nbformat' | |||
|
14 | 15 | |
|
15 | 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 | 24 | # Class declarations |
|
19 | 25 | #----------------------------------------------------------------------------- |
@@ -68,7 +74,7 b' class Converter(object):' | |||
|
68 | 74 | self.infile = infile |
|
69 | 75 | self.infile_dir, infile_root = os.path.split(infile) |
|
70 | 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 | 78 | if not os.path.isdir(files_dir): |
|
73 | 79 | os.mkdir(files_dir) |
|
74 | 80 | self.infile_root = infile_root |
@@ -168,7 +174,7 b' class Converter(object):' | |||
|
168 | 174 | |
|
169 | 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 | 178 | self.figures_counter, fmt) |
|
173 | 179 | self.figures_counter += 1 |
|
174 | 180 | fullname = os.path.join(self.files_dir, figname) |
General Comments 0
You need to be logged in to leave comments.
Login now