Conversion pipeline: Automatically change case of upper cased CSS tag selectors to lower case, so that they match

This commit is contained in:
Kovid Goyal 2010-01-11 16:16:11 -07:00
parent c3e62b073d
commit 70a53214b6
2 changed files with 12 additions and 2 deletions

View File

@ -168,6 +168,7 @@ class Stylizer(object):
self.rules = rules self.rules = rules
self._styles = {} self._styles = {}
class_sel_pat = re.compile(r'\.[a-z]+', re.IGNORECASE) class_sel_pat = re.compile(r'\.[a-z]+', re.IGNORECASE)
capital_sel_pat = re.compile(r'h|[A-Z]+')
for _, _, cssdict, text, _ in rules: for _, _, cssdict, text, _ in rules:
try: try:
selector = CSSSelector(text) selector = CSSSelector(text)
@ -176,6 +177,15 @@ class Stylizer(object):
SelectorSyntaxError): SelectorSyntaxError):
continue continue
matches = selector(tree) 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): if not matches and class_sel_pat.match(text):
found = False found = False
for x in tree.xpath('//*[@class]'): for x in tree.xpath('//*[@class]'):

View File

@ -7,7 +7,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>838</width> <width>884</width>
<height>730</height> <height>730</height>
</rect> </rect>
</property> </property>
@ -89,7 +89,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>562</width> <width>608</width>
<height>683</height> <height>683</height>
</rect> </rect>
</property> </property>