forked from LiveCarta/BookConverter
epub converter: prettify
This commit is contained in:
@@ -313,7 +313,7 @@ class EpubPostprocessor:
|
|||||||
if anchor_tag.attrs['id'] not in self.internal_anchors:
|
if anchor_tag.attrs['id'] not in self.internal_anchors:
|
||||||
new_anchor_span = self._create_new_anchor_span(soup, new_id)
|
new_anchor_span = self._create_new_anchor_span(soup, new_id)
|
||||||
anchor_tag.insert_before(new_anchor_span)
|
anchor_tag.insert_before(new_anchor_span)
|
||||||
self.internal_anchors.add(anchor_tag.attrs['id'])
|
self.internal_anchors.add(new_id)
|
||||||
del anchor_tag.attrs['id']
|
del anchor_tag.attrs['id']
|
||||||
del internal_link_tag.attrs['href']
|
del internal_link_tag.attrs['href']
|
||||||
|
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ def get_tags_between_chapter_marks(first_id, href, html_soup):
|
|||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def wrap_span_with_table(main_tag, old_tag):
|
def wrap_preformatted_span_with_table(main_tag, old_tag):
|
||||||
table = main_tag.new_tag("table")
|
table = main_tag.new_tag("table")
|
||||||
table.attrs['border'] = '1px solid #ccc;'
|
table.attrs['border'] = '1px solid #ccc;'
|
||||||
table.attrs['style'] = 'width:100%;'
|
table.attrs['style'] = 'width:100%;'
|
||||||
@@ -393,7 +393,7 @@ def wrap_span_with_table(main_tag, old_tag):
|
|||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
def wrap_block_with_table(main_tag, old_tag, color=None):
|
def wrap_block_tag_with_table(main_tag, old_tag, bg_color=None):
|
||||||
table = main_tag.new_tag("table")
|
table = main_tag.new_tag("table")
|
||||||
table.attrs['border'] = '1px solid'
|
table.attrs['border'] = '1px solid'
|
||||||
table.attrs['align'] = 'center'
|
table.attrs['align'] = 'center'
|
||||||
@@ -402,8 +402,8 @@ def wrap_block_with_table(main_tag, old_tag, color=None):
|
|||||||
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['border-radius'] = '8px'
|
# td.attrs['border-radius'] = '8px'
|
||||||
if color:
|
if bg_color:
|
||||||
td.attrs['bgcolor'] = color
|
td.attrs['bgcolor'] = bg_color
|
||||||
old_tag.wrap(td)
|
old_tag.wrap(td)
|
||||||
td.wrap(tr)
|
td.wrap(tr)
|
||||||
tr.wrap(tbody)
|
tr.wrap(tbody)
|
||||||
@@ -426,7 +426,7 @@ def preprocess_block_tags(chapter_tag):
|
|||||||
|
|
||||||
color = '#DDDDDD' if block.attrs.get('class') == 'feature1' else None
|
color = '#DDDDDD' if block.attrs.get('class') == 'feature1' else None
|
||||||
color = '#EEEEEE' if block.attrs.get('class') == 'feature2' else color
|
color = '#EEEEEE' if block.attrs.get('class') == 'feature2' else color
|
||||||
wrap_block_with_table(chapter_tag, block, color)
|
wrap_block_tag_with_table(chapter_tag, block, color)
|
||||||
block.insert_after(BeautifulSoup(features='lxml').new_tag("br"))
|
block.insert_after(BeautifulSoup(features='lxml').new_tag("br"))
|
||||||
block.unwrap()
|
block.unwrap()
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ def preprocess_pre_tags(chapter_tag):
|
|||||||
"font-size: 14px; white-space: nowrap;"
|
"font-size: 14px; white-space: nowrap;"
|
||||||
pre.insert_before(new_tag)
|
pre.insert_before(new_tag)
|
||||||
pre.extract()
|
pre.extract()
|
||||||
table = wrap_span_with_table(chapter_tag, new_tag)
|
table = wrap_preformatted_span_with_table(chapter_tag, new_tag)
|
||||||
p_for_br = chapter_tag.new_tag("p")
|
p_for_br = chapter_tag.new_tag("p")
|
||||||
p_for_br.string = "\xa0"
|
p_for_br.string = "\xa0"
|
||||||
table.insert_after(p_for_br)
|
table.insert_after(p_for_br)
|
||||||
|
|||||||
Reference in New Issue
Block a user