forked from LiveCarta/BookConverter
epub converter: fix <pre> 2
This commit is contained in:
@@ -389,7 +389,6 @@ def wrap_span_with_table(main_tag, old_tag):
|
|||||||
tbody = main_tag.new_tag("tbody")
|
tbody = main_tag.new_tag("tbody")
|
||||||
tr = main_tag.new_tag("tr")
|
tr = main_tag.new_tag("tr")
|
||||||
td = main_tag.new_tag("td")
|
td = main_tag.new_tag("td")
|
||||||
td.attrs['style'] = 'font-family: courier new,courier,monospace;'
|
|
||||||
td.attrs['bgcolor'] = '#f5f5f5'
|
td.attrs['bgcolor'] = '#f5f5f5'
|
||||||
old_tag.wrap(td)
|
old_tag.wrap(td)
|
||||||
td.wrap(tr)
|
td.wrap(tr)
|
||||||
@@ -400,18 +399,31 @@ def wrap_span_with_table(main_tag, old_tag):
|
|||||||
|
|
||||||
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.attrs = pre.attrs.copy()
|
||||||
|
|
||||||
for child in pre.children:
|
for child in pre.children:
|
||||||
if isinstance(child, NavigableString):
|
if isinstance(child, NavigableString):
|
||||||
child.text = escape(pre.text)
|
text = escape(pre.text)
|
||||||
pre.name = 'span'
|
text = text.replace('\t', ' ')
|
||||||
pre.attrs['style'] = "white-space: pre-wrap;"
|
elements = re.split('\r\n|\n|\r', text)
|
||||||
wrap_span_with_table(chapter_tag, pre)
|
for i in elements:
|
||||||
|
new_tag.append(NavigableString(i))
|
||||||
|
new_tag.append(BeautifulSoup().new_tag('br'))
|
||||||
|
else:
|
||||||
|
new_tag.append(child.extract())
|
||||||
|
|
||||||
|
new_tag.attrs['style'] = "font-family: courier new,courier,monospace; " \
|
||||||
|
"font-size: 14px; white-space: pre-wrap;"
|
||||||
|
pre.insert_before(new_tag)
|
||||||
|
pre.extract()
|
||||||
|
wrap_span_with_table(chapter_tag, new_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("code"):
|
||||||
code.name = 'span'
|
code.name = 'span'
|
||||||
code.attrs['style'] = 'color:#c7254e; font-family: courier new,courier,monospace;'
|
code.attrs['style'] = 'color:#c7254e; font-size: 14px; font-family: courier new,courier,monospace;'
|
||||||
|
|
||||||
|
|
||||||
def prepare_title_and_content(title, chapter_tag: BeautifulSoup, remove_title_from_chapter) -> Tuple[str, str]:
|
def prepare_title_and_content(title, chapter_tag: BeautifulSoup, remove_title_from_chapter) -> Tuple[str, str]:
|
||||||
|
|||||||
Reference in New Issue
Block a user