From 70a53214b6a7ed3a03caf933412448e91a50fc6f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Jan 2010 16:16:11 -0700 Subject: [PATCH] Conversion pipeline: Automatically change case of upper cased CSS tag selectors to lower case, so that they match --- src/calibre/ebooks/oeb/stylizer.py | 10 ++++++++++ src/calibre/gui2/dialogs/config/config.ui | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index d986033418..9f50796615 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -168,6 +168,7 @@ class Stylizer(object): self.rules = rules self._styles = {} class_sel_pat = re.compile(r'\.[a-z]+', re.IGNORECASE) + capital_sel_pat = re.compile(r'h|[A-Z]+') for _, _, cssdict, text, _ in rules: try: selector = CSSSelector(text) @@ -176,6 +177,15 @@ class Stylizer(object): SelectorSyntaxError): continue matches = selector(tree) + + if not matches: + ntext = capital_sel_pat.sub(lambda m: m.group().lower(), text) + if ntext != text: + self.logger.warn('Transformed CSS selector', text, 'to', + ntext) + selector = CSSSelector(ntext) + matches = selector(tree) + if not matches and class_sel_pat.match(text): found = False for x in tree.xpath('//*[@class]'): diff --git a/src/calibre/gui2/dialogs/config/config.ui b/src/calibre/gui2/dialogs/config/config.ui index e638bab1c9..b9306b0f10 100644 --- a/src/calibre/gui2/dialogs/config/config.ui +++ b/src/calibre/gui2/dialogs/config/config.ui @@ -7,7 +7,7 @@ 0 0 - 838 + 884 730 @@ -89,7 +89,7 @@ 0 0 - 562 + 608 683