From fae59d74ebd61eb857fa450231d14a77a1156e8d Mon Sep 17 00:00:00 2001 From: Kibzik Date: Wed, 10 May 2023 16:11:16 +0300 Subject: [PATCH] LAW-6695 | Add span with id in _remove_headings_content --- src/html_presets_processor.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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: