def transform_css(self): transform_css(self, transform_sheet=transform_sheet, transform_style=transform_declaration) # Firefox flakes out sometimes when dynamically creating <style> tags, # so convert them to external stylesheets to ensure they never fail style_xpath = XPath('//h:style') for name, mt in tuple(self.mime_map.iteritems()): mt = mt.lower() if mt in OEB_DOCS: head = ensure_head(self.parsed(name)) for style in style_xpath(self.parsed(name)): if style.text and (style.get('type') or 'text/css').lower() == 'text/css': in_head = has_ancestor(style, head) if not in_head: extract(style) head.append(style) css = style.text style.clear() style.tag = XHTML('link') style.set('type', 'text/css') style.set('rel', 'stylesheet') sname = self.add_file(name + '.css', css.encode('utf-8'), modify_name_if_needed=True) style.set('href', self.name_to_href(sname, name))
def transform_container(container, serialized_rules, names=()): from calibre.ebooks.oeb.polish.css import transform_css rules = compile_rules(serialized_rules) return transform_css(container, transform_sheet=partial(transform_sheet, rules), transform_style=partial(transform_declaration, rules), names=names)
def transform_container(container, serialized_rules, names=()): from calibre.ebooks.oeb.polish.css import transform_css rules = compile_rules(serialized_rules) return transform_css( container, transform_sheet=partial(transform_sheet, rules), transform_style=partial(transform_declaration, rules), names=names )
def transform_css(self): transform_css(self, transform_sheet=transform_sheet, transform_style=transform_declaration)