forked from LiveCarta/BookConverter
epub converter: update pre
This commit is contained in:
@@ -431,6 +431,14 @@ def preprocess_block_tags(chapter_tag):
|
|||||||
block.unwrap()
|
block.unwrap()
|
||||||
|
|
||||||
|
|
||||||
|
def _prepare_formatted(text):
|
||||||
|
text = text.replace("<", "\x3C;")
|
||||||
|
text = text.replace(">", "\x3E;")
|
||||||
|
text = text.replace('\t', "\xa0 \xa0 \xa0 ")
|
||||||
|
text = text.replace(' ', "\xa0 ")
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def preprocess_pre_tags(chapter_tag):
|
def preprocess_pre_tags(chapter_tag):
|
||||||
for pre in chapter_tag.find_all("pre"):
|
for pre in chapter_tag.find_all("pre"):
|
||||||
new_tag = BeautifulSoup(features='lxml').new_tag("span")
|
new_tag = BeautifulSoup(features='lxml').new_tag("span")
|
||||||
@@ -441,15 +449,13 @@ 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("<", "\x3C;")
|
text = _prepare_formatted(text)
|
||||||
text = text.replace(">", "\x3E;")
|
|
||||||
text = text.replace('\t', "\xa0 \xa0 \xa0 ")
|
|
||||||
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(features='lxml').new_tag('br'))
|
new_tag.append(BeautifulSoup(features='lxml').new_tag('br'))
|
||||||
else:
|
else:
|
||||||
|
child.string = _prepare_formatted(child.text)
|
||||||
new_tag.append(child.extract())
|
new_tag.append(child.extract())
|
||||||
if to_add_br:
|
if to_add_br:
|
||||||
new_tag.append(BeautifulSoup(features='lxml').new_tag('br'))
|
new_tag.append(BeautifulSoup(features='lxml').new_tag('br'))
|
||||||
|
|||||||
Reference in New Issue
Block a user