From c1cebf32b9e794266a5f2634857f2ca5bab7ce50 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Fri, 29 Apr 2022 17:46:19 +0300 Subject: [PATCH] Fix: code is transferred incorrectly --- src/epub_converter/html_epub_preprocessor.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/epub_converter/html_epub_preprocessor.py b/src/epub_converter/html_epub_preprocessor.py index d340586..ff2af37 100644 --- a/src/epub_converter/html_epub_preprocessor.py +++ b/src/epub_converter/html_epub_preprocessor.py @@ -593,18 +593,22 @@ def preprocess_pre_tags(chapter_tag: BeautifulSoup): for pre in chapter_tag.find_all("pre"): new_tag = BeautifulSoup(features='lxml').new_tag("span") new_tag.attrs = pre.attrs.copy() - spans = pre.find_all("span") + new_tag.attrs['style'] = "font-family: courier new,courier,monospace; " \ + "font-size: 14px; white-space: nowrap;" # if in
 there are multiple , we need to add 
after each content - to_add_br = len(spans) > 1 + to_add_br = len(pre.find_all("span")) > 1 copy_contents = pre.contents[:] for child in copy_contents: + # Navigable String if isinstance(child, NavigableString): cleaned_text = prepare_formatted(str(child)) sub_strings = re.split('\r\n|\n|\r', cleaned_text) - for string in sub_strings: + for string in sub_strings[:-1]: new_tag.append(NavigableString(string)) new_tag.append(BeautifulSoup( features='lxml').new_tag('br')) + new_tag.append(NavigableString(sub_strings[-1])) + # Tag else: for sub_child in child.children: if isinstance(sub_child, NavigableString): @@ -617,9 +621,6 @@ def preprocess_pre_tags(chapter_tag: BeautifulSoup): if to_add_br: new_tag.append(BeautifulSoup( features='lxml').new_tag('br')) - - new_tag.attrs['style'] = "font-family: courier new,courier,monospace; " \ - "font-size: 14px; white-space: nowrap;" pre.replace_with(new_tag) table = wrap_preformatted_span_with_table(chapter_tag, new_tag) # add

to save brs