diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index 678c21f4ab..a53e6050d1 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -652,6 +652,7 @@ OptionRecommendation(name='list_recipes', line_height = self.opts.line_height if line_height < 1e-4: line_height = None + flattener = CSSFlattener(fbase=fbase, fkey=fkey, lineh=line_height, untable=self.output_plugin.file_type in ('mobi','lit'), diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index a2d999ffc8..04db679a6c 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -103,6 +103,7 @@ class MobiMLizer(object): self.oeb.manifest.remove(item) def mobimlize_spine(self): + 'Iterate over the spine and convert it to MOBIML' for item in self.oeb.spine: stylizer = Stylizer(item.data, item.href, self.oeb, self.profile) body = item.data.find(XHTML('body')) @@ -136,6 +137,7 @@ class MobiMLizer(object): return result def mobimlize_content(self, tag, text, bstate, istates): + 'Convert text content' if text or tag != 'br': bstate.content = True istate = istates[-1] diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index daf5d21d2a..8b0667c8b7 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -157,6 +157,7 @@ class Stylizer(object): rules.sort() self.rules = rules self._styles = {} + class_sel_pat = re.compile(r'\.[a-z]+', re.IGNORECASE) for _, _, cssdict, text, _ in rules: try: selector = CSSSelector(text) @@ -164,7 +165,17 @@ class Stylizer(object): NameError, # thrown on OS X instead of SelectorSyntaxError SelectorSyntaxError): continue - for elem in selector(tree): + matches = selector(tree) + if not matches and class_sel_pat.match(text): + found = False + for x in tree.xpath('//*[@class]'): + if x.get('class').lower() == text[1:].lower(): + matches.append(x) + found = True + if found: + self.logger.warn('Ignoring case mismatch for CSS selector: %s in %s' + %(text, item.href)) + for elem in matches: self.style(elem)._update_cssdict(cssdict) for elem in xpath(tree, '//h:*[@style]'): self.style(elem)._apply_style_attr() diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 49119ecb9b..9f5deb5404 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -141,7 +141,6 @@ class CSSFlattener(object): bs.append('text-align: '+ \ ('left' if self.context.dont_justify else 'justify')) body.set('style', '; '.join(bs)) - stylizer = Stylizer(html, item.href, self.oeb, profile, user_css=self.context.extra_css, extra_css=css)