forked from LiveCarta/BookConverter
epub converter: fix tables
This commit is contained in:
@@ -68,7 +68,7 @@ def preprocess_figure():
|
|||||||
def preprocess_table(body_tag: BeautifulSoup):
|
def preprocess_table(body_tag: BeautifulSoup):
|
||||||
tables = body_tag.find_all("table")
|
tables = body_tag.find_all("table")
|
||||||
for table in tables:
|
for table in tables:
|
||||||
tds = table.find_all("td")
|
tds = table.find_all(re.compile("td|th|tr"))
|
||||||
|
|
||||||
border_sizes = []
|
border_sizes = []
|
||||||
for td in tds:
|
for td in tds:
|
||||||
@@ -101,6 +101,9 @@ def preprocess_table(body_tag: BeautifulSoup):
|
|||||||
if td.attrs.get('style'):
|
if td.attrs.get('style'):
|
||||||
td.attrs['style'] = td.attrs['style'].replace('border:0;', '')
|
td.attrs['style'] = td.attrs['style'].replace('border:0;', '')
|
||||||
|
|
||||||
|
if td.attrs.get('style') == '':
|
||||||
|
del td.attrs['style']
|
||||||
|
|
||||||
if border_sizes:
|
if border_sizes:
|
||||||
border_size = sum(border_sizes) / len(border_sizes)
|
border_size = sum(border_sizes) / len(border_sizes)
|
||||||
table.attrs['border'] = f'{border_size:.2}'
|
table.attrs['border'] = f'{border_size:.2}'
|
||||||
|
|||||||
Reference in New Issue
Block a user