diff --git a/src/html_presets_processor.py b/src/html_presets_processor.py
index af7a88d..962f9c9 100644
--- a/src/html_presets_processor.py
+++ b/src/html_presets_processor.py
@@ -116,11 +116,21 @@ class HtmlPresetsProcessor:
new_tag.string = "\xa0"
tag_to_be_removed.insert_before(new_tag)
- if tag_to_be_removed.attrs.get("id"):
+ def has_child_with_id(tag):
+ """
+ Check if any child tag has an 'id' attribute.
+ """
+ for child in tag.children:
+ if child.has_attr('id'):
+ return child
+ return False
+
+ child_with_id = has_child_with_id(tag_to_be_removed)
+ if tag_to_be_removed.attrs.get("id") or child_with_id:
_insert_span_with_attrs_before_tag(chapter_tag=chapter_tag,
tag_to_be_removed=tag_to_be_removed,
- id_=tag_to_be_removed.attrs["id"],
- class_=tag_to_be_removed.attrs.get("class"))
+ id_=tag_to_be_removed.attrs["id"] if tag_to_be_removed.attrs.get("id") else child_with_id.attrs["id"],
+ class_=tag_to_be_removed.attrs["class"] if tag_to_be_removed.attrs.get("id") else child_with_id.attrs.get("class"))
def _process_tag_using_table(self, **kwargs):
def _wrap_tag_with_table(width: str = "100", border: str = "", bg_color: str = None) -> Tag: