mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Edit book: Reports: Include descendant selectors that use classes when counting class usage. Fixes #1954839 [Style classes wrongly reported as 0 (unused)](https://bugs.launchpad.net/calibre/+bug/1954839)
This commit is contained in:
parent
8c2aa4182c
commit
c1dc45a79f
@ -297,10 +297,21 @@ def css_data(container, book_locale, result_data, *args):
|
||||
matches = tuple(select(selector))
|
||||
except SelectorError:
|
||||
return ()
|
||||
for elem in matches:
|
||||
for cls in elem.get('class', '').split():
|
||||
if '.' + cls.lower() in lsel:
|
||||
class_map[cls][elem].append(rule)
|
||||
seen = set()
|
||||
|
||||
def get_elem_and_ancestors(elem):
|
||||
p = elem
|
||||
while p is not None:
|
||||
if p not in seen:
|
||||
yield p
|
||||
seen.add(p)
|
||||
p = p.getparent()
|
||||
|
||||
for e in matches:
|
||||
for elem in get_elem_and_ancestors(e):
|
||||
for cls in elem.get('class', '').split():
|
||||
if '.' + cls.lower() in lsel:
|
||||
class_map[cls][elem].append(rule)
|
||||
|
||||
return (MatchLocation(tag_text(elem), elem.sourceline) for elem in matches)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user