diff --git a/src/calibre/ebooks/epub/from_html.py b/src/calibre/ebooks/epub/from_html.py index afd0af73d7..ffe402538f 100644 --- a/src/calibre/ebooks/epub/from_html.py +++ b/src/calibre/ebooks/epub/from_html.py @@ -205,9 +205,8 @@ class HTMLProcessor(Processor, Rationalizer): def save(self): for meta in list(self.root.xpath('//meta')): meta.getparent().remove(meta) - #for img in self.root.xpath('//img[@src]'): - # self.convert_image(img) - Processor.save(self) + # Strip all comments since Adobe DE is petrified of them + Processor.save(self, strip_comments=True) def remove_first_image(self): images = self.root.xpath('//img') diff --git a/src/calibre/ebooks/html.py b/src/calibre/ebooks/html.py index 340f5636eb..1c15973d3b 100644 --- a/src/calibre/ebooks/html.py +++ b/src/calibre/ebooks/html.py @@ -332,8 +332,6 @@ class PreProcessor(object): (re.compile(r'&(\S+?);'), convert_entities), # Remove the ]*>'), lambda match: ''), - # Strip all comments since Adobe DE is petrified of them - (re.compile(r'', re.DOTALL).sub('', ans) with open(self.save_path(), 'wb') as f: f.write(ans) return f.name @@ -594,7 +596,7 @@ class Processor(Parser): mark = etree.Element('hr', style=page_break_before) elem.addprevious(mark) - def save(self): + def save(self, strip_comments=False): style_path = os.path.splitext(os.path.basename(self.save_path()))[0] for i, sheet in enumerate([self.stylesheet, self.font_css, self.override_css]): if sheet is not None: @@ -608,7 +610,7 @@ class Processor(Parser): if isinstance(raw, unicode): raw = raw.encode('utf-8') open(path, 'wb').write(raw) - return Parser.save(self) + return Parser.save(self, strip_comments=strip_comments) def populate_toc(self, toc): '''