From 4c9197d95095ed41ea48980eda89ed8d3c47c468 Mon Sep 17 00:00:00 2001 From: "St.Huang" Date: Sun, 8 Jul 2018 18:59:07 +0800 Subject: [PATCH] auto-copy missing css file from mdx path if it's exist. --- src/fastwq/service/base.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/fastwq/service/base.py b/src/fastwq/service/base.py index de3d764..1b82c95 100644 --- a/src/fastwq/service/base.py +++ b/src/fastwq/service/base.py @@ -539,14 +539,17 @@ class MdxService(LocalService): r']+?href=\"(sound:_.*?\.(?:mp3|wav))\"[^>]*?>(.*?)') html = p.sub(u"[\\1]\\2", html) self.save_media_files(media_files_set) - for cssfile in mcss: - cssfile = '_' + \ - os.path.basename(cssfile.replace('\\', os.path.sep)) + for f in mcss: + cssfile = u'_{}'.format(os.path.basename(f.replace('\\', os.path.sep))) # if not exists the css file, the user can place the file to media # folder first, and it will also execute the wrap process to generate # the desired file. if not os.path.exists(cssfile): - self.missed_css.add(cssfile[1:]) + css_src = self.dict_path.replace(self._filename+u'.mdx', f) + if os.path.exists(css_src): + shutil.copy(css_src, cssfile) + else: + self.missed_css.add(cssfile[1:]) new_css_file, wrap_class_name = wrap_css(cssfile) html = html.replace(cssfile, new_css_file) # add global div to the result html