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:
Kovid Goyal 2021-12-15 10:46:17 +05:30
parent 8c2aa4182c
commit c1dc45a79f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

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