diff --git a/src/html_presets_processor.py b/src/html_presets_processor.py
index 5f5bae3..30f7906 100644
--- a/src/html_presets_processor.py
+++ b/src/html_presets_processor.py
@@ -117,7 +117,7 @@ class HtmlPresetsProcessor:
@staticmethod
def _insert_tag(**kwargs):
tag_to_insert = \
- kwargs["chapter_tag"].new_tag(kwargs["rule"]["tag_to_insert"])
+ kwargs["body_tag"].new_tag(kwargs["rule"]["tag_to_insert"])
# insert all items that was in tag to subtag and remove from tag
for content in reversed(kwargs["tag"].contents):
tag_to_insert.insert(0, content.extract())
@@ -150,14 +150,15 @@ class HtmlPresetsProcessor:
if rule["condition"]:
for condition_on_tag in ((k, v) for k, v in rule["condition"].items() if v):
if condition_on_tag[0] == "parent_tags":
- for tag in body_tag.select(', '.join([condition_on_tag[1] + " > " + re.sub(r"[\^$]", "", tag)
- for tag in tags])):
- tag.parent.attrs.update(tag.attrs)
- action(body_tag=body_tag, tag=tag, rule=rule)
+ for parent_tag in body_tag.select(condition_on_tag[1]):
+ for tag in parent_tag.find_all([re.compile(tag) for tag in tags]):
+ # parent_tag != tag.parent
+ tag.parent.attrs.update(tag.attrs)
+ action(body_tag=body_tag, tag=tag, rule=rule)
elif condition_on_tag[0] == "child_tags":
- for tag in body_tag.select(', '.join([re.sub(r"[\^$]", "", tag) + condition_on_tag[1]
- for tag in tags])):
- action(body_tag=body_tag, tag=tag, rule=rule)
+ for tag in body_tag.find_all([re.compile(tag) for tag in tags]):
+ if tag.select(condition_on_tag[1]):
+ action(body_tag=body_tag, tag=tag, rule=rule)
elif condition_on_tag[0] == "attrs":
for attr in rule["condition"]["attrs"]:
for tag in body_tag.find_all([re.compile(tag) for tag in tags],