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