forked from LiveCarta/BookConverter
Fix duplicate tags cause of dict.get(key) = 0
This commit is contained in:
@@ -34,15 +34,11 @@ class HtmlPresetsProcessor:
|
|||||||
def _tags_with_parent_condition(**kwargs):
|
def _tags_with_parent_condition(**kwargs):
|
||||||
found_tags: list[Tag] = list()
|
found_tags: list[Tag] = list()
|
||||||
# add unique id in order not to add duplicates to the
|
# add unique id in order not to add duplicates to the
|
||||||
# found_tags(because tag with subtag could duplicate found_tag)
|
# found_tags(because parent_tag with sub parent_tag could be a duplicate found_tag)
|
||||||
u_id = 0
|
|
||||||
for parent_tag in kwargs["body_tag"].select(kwargs["family_condition"]):
|
for parent_tag in kwargs["body_tag"].select(kwargs["family_condition"]):
|
||||||
for tag in parent_tag.find_all([re.compile(tag) for tag in kwargs["tags"]]):
|
for tag in parent_tag.find_all([re.compile(tag) for tag in kwargs["tags"]]):
|
||||||
if not tag.attrs.get("unique_id"):
|
|
||||||
tag.attrs["unique_id"] = u_id
|
|
||||||
u_id += 1
|
|
||||||
found_tags.append(tag)
|
found_tags.append(tag)
|
||||||
return len(found_tags) != 0, list(found_tags)
|
return len(found_tags) != 0, list(set(found_tags))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _tags_with_child_condition(**kwargs):
|
def _tags_with_child_condition(**kwargs):
|
||||||
@@ -184,6 +180,7 @@ class HtmlPresetsProcessor:
|
|||||||
def _unwrap_tag(self, **kwargs):
|
def _unwrap_tag(self, **kwargs):
|
||||||
if kwargs["found_tag"].parent:
|
if kwargs["found_tag"].parent:
|
||||||
self.set_attrs_to_parent(kwargs["found_tag"], kwargs["found_tag"].parent)
|
self.set_attrs_to_parent(kwargs["found_tag"], kwargs["found_tag"].parent)
|
||||||
|
print(kwargs["found_tag"])
|
||||||
kwargs["found_tag"].unwrap()
|
kwargs["found_tag"].unwrap()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user