Ignore case mismatches in CSS class based selectors. This mimics the behavior of several HTML/CSS renderers, including gecko and mshtml

This commit is contained in:
Kovid Goyal 2009-06-23 20:19:55 -07:00
parent c4dd95aaa9
commit 4739423f97
3 changed files with 13 additions and 2 deletions

View File

@ -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'),

View File

@ -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()

View File

@ -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)