LAW-6736 | Change process of replacing text from string to nodes

This commit is contained in:
Kibzik
2023-05-29 12:26:55 +03:00
parent 377bb4f410
commit e9391081ff

View File

@@ -262,15 +262,10 @@ class HtmlPresetsProcessor:
@staticmethod @staticmethod
def _replace_text(**kwargs): def _replace_text(**kwargs):
found_tag_text = kwargs["found_tag"].string if kwargs["found_tag"].string is not None\ # Replace the regex pattern with "approaches" in the text nodes within the tag
else kwargs["found_tag"].text for text_node in kwargs["found_tag"].find_all(text=True):
if found_tag_text is not None and re.search(re.compile(kwargs["rule"]["condition"]["text"]), found_tag_text): text_node.replace_with(re.sub(kwargs["rule"]["condition"]["text"],
new_text = re.sub(re.compile( kwargs["rule"]["text_to_replace"], str(text_node)))
kwargs["rule"]["condition"]["text"]), kwargs["rule"]["text_to_replace"], found_tag_text)
if kwargs["found_tag"].string is not None:
kwargs["found_tag"].string.replace_with(new_text)
else:
kwargs["found_tag"].string = new_text
def process_tags(self, def process_tags(self,
body_tag: BeautifulSoup, body_tag: BeautifulSoup,