forked from LiveCarta/BookConverter
Fix text replacer to have text or string as option
This commit is contained in:
@@ -260,13 +260,14 @@ class HtmlPresetsProcessor:
|
||||
|
||||
@staticmethod
|
||||
def _replace_text(**kwargs):
|
||||
try:
|
||||
if re.search(re.compile(kwargs["rule"]["condition"]["text"]), kwargs["found_tag"].string):
|
||||
new_text = re.sub(re.compile(
|
||||
kwargs["rule"]["condition"]["text"]), kwargs["rule"]["text_to_replace"], kwargs["found_tag"].string)
|
||||
found_tag_text = kwargs["found_tag"].string or kwargs["found_tag"].text
|
||||
if found_tag_text is not None and re.search(re.compile(kwargs["rule"]["condition"]["text"]), found_tag_text):
|
||||
new_text = re.sub(re.compile(
|
||||
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)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
kwargs["found_tag"].string = new_text
|
||||
|
||||
def process_tags(self,
|
||||
body_tag: BeautifulSoup,
|
||||
|
||||
Reference in New Issue
Block a user