Edit book: When renaming classes in style sheets only recognize class names preceded by a period. Fixes #1944562 [Renaming class called "body" renames rules for body element](https://bugs.launchpad.net/calibre/+bug/1944562)

This commit is contained in:
Kovid Goyal 2021-09-22 20:34:37 +05:30
parent ef2e2c714c
commit d12e14b236
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -501,7 +501,10 @@ def add_stylesheet_links(container, name, text):
def rename_class_in_rule_list(css_rules, old_name, new_name):
pat = re.compile(rf'\b{re.escape(old_name)}\b')
# this regex will not match class names inside attribute value selectors
# and it will match id selectors that contain .old_name but its the best
# that can be done without implementing a full parser for CSS selectors
pat = re.compile(rf'(?<=\.){re.escape(old_name)}\b')
changed = False
for rule in css_rules:
if rule.type == rule.STYLE_RULE: