mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
c4dd95aaa9
commit
4739423f97
@ -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'),
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user