From 25320816b546bc7baf7c577e5131f61033aecd2e Mon Sep 17 00:00:00 2001 From: shirshasa Date: Mon, 2 Aug 2021 11:28:03 +0300 Subject: [PATCH] epub converter: prettify tables processing --- src/html_epub_preprocessor.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/html_epub_preprocessor.py b/src/html_epub_preprocessor.py index 1e01690..36cd35b 100644 --- a/src/html_epub_preprocessor.py +++ b/src/html_epub_preprocessor.py @@ -72,25 +72,11 @@ def preprocess_table(body_tag: BeautifulSoup): tables = body_tag.find_all("table") for table in tables: tds = table.find_all(re.compile("td|th|tr")) - - border_sizes = [] for td in tds: style = td.get('style') width = '' if style: - border_match = re.search(r"border: ?(\d+\.?\d*)(p[tx])", style) or\ - re.search(r"border-top-width: ?(\d+\.?\d*)(p[tx])", style) or\ - re.search(r"border-left-width: ?(\d+\.?\d*)(p[tx])", style) or \ - re.search(r"border-right-width: ?(\d+\.?\d*)(p[tx])", style) or \ - re.search(r"border-bottom-width: ?(\d+\.?\d*)(p[tx])", style) - - if border_match: - size = border_match.group(1) - units = border_match.group(2) - border_sizes.append(float(size)) - width_match = re.search(r"[^-]width: ?(\d+\.?\d*)(p[tx])", style) - if width_match: size = width_match.group(1) units = width_match.group(2) @@ -107,10 +93,7 @@ def preprocess_table(body_tag: BeautifulSoup): 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}' - else: + if not table.attrs.get('border') or table.attrs.get('border') in ['0', '0px']: table.attrs['border'] = '1'