From 1b94b870a7cc5c493b68cd25f5193cfb94a4f140 Mon Sep 17 00:00:00 2001 From: shirshasa Date: Wed, 2 Jun 2021 08:41:46 +0300 Subject: [PATCH] epub converter: bug fix - remove adding border 0 in td -save links while headings removal --- src/html_epub_preprocessor.py | 12 ++++++++++++ src/livecarta_config.py | 3 ++- src/util/color_reader.py | 4 +--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/html_epub_preprocessor.py b/src/html_epub_preprocessor.py index d2c4a33..e7a3958 100644 --- a/src/html_epub_preprocessor.py +++ b/src/html_epub_preprocessor.py @@ -97,6 +97,7 @@ def preprocess_table(body_tag: BeautifulSoup): if width: td.attrs['width'] = width + td.attrs['style'] = td.attrs.get('style').replace('border:0;', '') if border_sizes: border_size = sum(border_sizes) / len(border_sizes) @@ -118,6 +119,15 @@ def _process_lists(body_tag): il_tag.p.unwrap() +def _add_span_to_save_ids_for_links(tag_to_be_removed, body_tag): + for sub_tag in tag_to_be_removed.find_all(): + if sub_tag.attrs.get('id'): + new_tag = body_tag.new_tag("span") + new_tag.attrs['id'] = sub_tag.attrs['id'] + new_tag.attrs['class'] = sub_tag.attrs.get('class') + tag_to_be_removed.insert_before(new_tag) + + def clean_headings_content(content: Tag, title: str): title = title.lower() for child in content.contents: @@ -130,8 +140,10 @@ def clean_headings_content(content: Tag, title: str): text = re.sub(r' +', ' ', text).strip() text = text.lower() if title == text: + _add_span_to_save_ids_for_links(child, content) child.extract() elif (title in text) and (child.name in ['h1', 'h2', 'h3']): + _add_span_to_save_ids_for_links(child, content) child.extract() break diff --git a/src/livecarta_config.py b/src/livecarta_config.py index d4f9743..31acc5e 100644 --- a/src/livecarta_config.py +++ b/src/livecarta_config.py @@ -104,7 +104,8 @@ class LawCartaConfig: 'silver': 'lightGray', 'white': 'white', 'maroon': '#800000', - 'gray': '#808080' + 'gray': '#808080', + 'grey': '#808080' } INDENT = '30px' diff --git a/src/util/color_reader.py b/src/util/color_reader.py index 45cc8dd..4c0be6b 100644 --- a/src/util/color_reader.py +++ b/src/util/color_reader.py @@ -59,9 +59,7 @@ def str2color_name(s: str): elif '#' in s: name = get_hex_color_name(s) if (name == 'white') and (s.lower() not in ['#ffffff', '#fff']): - return 'gray' - if name == 'grey': - return 'gray' + name = 'gray' return name