epub converter: fix tables

This commit is contained in:
shirshasa
2021-07-05 08:59:57 +03:00
parent b683c2127a
commit b435db052b

View File

@@ -68,7 +68,7 @@ def preprocess_figure():
def preprocess_table(body_tag: BeautifulSoup):
tables = body_tag.find_all("table")
for table in tables:
tds = table.find_all("td")
tds = table.find_all(re.compile("td|th|tr"))
border_sizes = []
for td in tds:
@@ -101,6 +101,9 @@ def preprocess_table(body_tag: BeautifulSoup):
if td.attrs.get('style'):
td.attrs['style'] = td.attrs['style'].replace('border:0;', '')
if td.attrs.get('style') == '':
del td.attrs['style']
if border_sizes:
border_size = sum(border_sizes) / len(border_sizes)
table.attrs['border'] = f'{border_size:.2}'