epub converter: fix <pre> 4

This commit is contained in:
shirshasa
2021-07-07 11:41:43 +03:00
parent 1f91be8f4b
commit 29697bfe12

View File

@@ -405,12 +405,12 @@ def preprocess_pre_tags(chapter_tag):
for child in pre.children: for child in pre.children:
if isinstance(child, NavigableString): if isinstance(child, NavigableString):
text = pre.text text = pre.text
text = text.replace('\t', '&nbsp; &nbsp; &nbsp; ') text = text.replace('\t', "\xa0 \xa0 \xa0 ")
text = text.replace(' ', '&nbsp; ') text = text.replace(' ', "\xa0 ")
elements = re.split('\r\n|\n|\r', text) elements = re.split('\r\n|\n|\r', text)
for i in elements: for i in elements:
new_tag.append(NavigableString(i)) new_tag.append(NavigableString(i))
new_tag.append(BeautifulSoup().new_tag('br')) new_tag.append(BeautifulSoup(features='lxml').new_tag('br'))
else: else:
new_tag.append(child.extract()) new_tag.append(child.extract())
@@ -422,7 +422,7 @@ def preprocess_pre_tags(chapter_tag):
def preprocess_code_tags(chapter_tag): def preprocess_code_tags(chapter_tag):
for code in chapter_tag.find_all("code"): for code in chapter_tag.find_all(re.compile("code|kdb|var")):
code.name = 'span' code.name = 'span'
code.attrs['style'] = 'color:#c7254e; font-size: 14px; font-family: courier new,courier,monospace;' code.attrs['style'] = 'color:#c7254e; font-size: 14px; font-family: courier new,courier,monospace;'