From b435db052b96a6c1b0a26650efdeb3a230ba8de1 Mon Sep 17 00:00:00 2001 From: shirshasa Date: Mon, 5 Jul 2021 08:59:57 +0300 Subject: [PATCH] epub converter: fix tables --- src/html_epub_preprocessor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/html_epub_preprocessor.py b/src/html_epub_preprocessor.py index f227a9c..ed38dab 100644 --- a/src/html_epub_preprocessor.py +++ b/src/html_epub_preprocessor.py @@ -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}'