leave similar tags

This commit is contained in:
Kibzik
2023-05-25 11:47:55 +03:00
parent 0481f5e98f
commit f97be684c7

View File

@@ -51,7 +51,6 @@ class HtmlPresetsProcessor:
@staticmethod
def _tags_with_attrs_condition(**kwargs):
found_tags: list[Tag] = list()
names = [attr["name"] for attr in kwargs["rule"]["condition"]["attrs"]]
values = [re.compile(attr["value"]) for attr in kwargs["rule"]["condition"]["attrs"]]
attr_conditions: dict[str, re] = dict(zip(names, values))
@@ -307,10 +306,11 @@ class HtmlPresetsProcessor:
found_tags = found_tags + f_tags if was_found else []
if not was_found:
break
# if there are several conditions on tags and found_tags isn't empty
# If there are several conditions on tags and found_tags isn't empty
if len(conditions_on_tag) > 1 and found_tags:
# tags satisfying all conditions((more than 1 condition)
found_tags = [tag for tag in found_tags if found_tags.count(tag) == len(conditions_on_tag)]
# Leave only tags satisfying all conditions(more than 1 condition)
# >= because there can be similar tags
found_tags = [tag for tag in found_tags if found_tags.count(tag) >= len(conditions_on_tag)]
# Make an action with necessary tags
for found_tag in found_tags: