From b6d86bcb8d1b7a013d5c0830e7773be3a7cfb404 Mon Sep 17 00:00:00 2001 From: shirshasa Date: Thu, 8 Jul 2021 16:53:28 +0300 Subject: [PATCH] epub converter: fix code in pre --- src/html_epub_preprocessor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/html_epub_preprocessor.py b/src/html_epub_preprocessor.py index 9cd431f..3160c88 100644 --- a/src/html_epub_preprocessor.py +++ b/src/html_epub_preprocessor.py @@ -385,7 +385,7 @@ def wrap_span_with_table(main_tag, old_tag): tr = main_tag.new_tag("tr") td = main_tag.new_tag("td") td.attrs['bgcolor'] = '#f5f5f5' - td.attrs['border-radius'] = '4px' + # td.attrs['border-radius'] = '4px' old_tag.wrap(td) td.wrap(tr) tr.wrap(tbody) @@ -401,7 +401,7 @@ def wrap_block_with_table(main_tag, old_tag, color=None): tbody = main_tag.new_tag("tbody") tr = main_tag.new_tag("tr") td = main_tag.new_tag("td") - td.attrs['border-radius'] = '8px' + # td.attrs['border-radius'] = '8px' if color: td.attrs['bgcolor'] = color old_tag.wrap(td) @@ -435,6 +435,8 @@ def preprocess_pre_tags(chapter_tag): 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") + to_add_br = len(spans) > 1 for child in pre.children: if isinstance(child, NavigableString): @@ -449,6 +451,8 @@ def preprocess_pre_tags(chapter_tag): new_tag.append(BeautifulSoup(features='lxml').new_tag('br')) else: new_tag.append(child.extract()) + 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: pre-wrap;" @@ -463,6 +467,8 @@ def preprocess_pre_tags(chapter_tag): def preprocess_code_tags(chapter_tag): for code in chapter_tag.find_all(re.compile("code|kdb|var")): code.name = 'span' + if code.parent.name == "pre": + continue code.attrs['style'] = 'color:#c7254e; font-size: 14px; font-family: courier new,courier,monospace;'