forked from LiveCarta/BookConverter
epub converter: fix code in pre
This commit is contained in:
@@ -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;'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user