From dcec9bad2e0bfd9e4fef255985dd90d75b754da2 Mon Sep 17 00:00:00 2001 From: Kiryl Date: Tue, 21 Jun 2022 16:16:42 +0300 Subject: [PATCH] Fix style problem with span --- src/epub_converter/tag_css_style_converter.py | 14 +++++++------- src/livecarta_config.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/epub_converter/tag_css_style_converter.py b/src/epub_converter/tag_css_style_converter.py index 269d8ed..eb6bb73 100644 --- a/src/epub_converter/tag_css_style_converter.py +++ b/src/epub_converter/tag_css_style_converter.py @@ -16,7 +16,7 @@ class TagStyleConverter: def __init__(self, tag_inline_style): # tag with inline style + style parsed from css file self.tag_inline_style = tag_inline_style - self.style = self.process_inline_style() + self.tag_inline_style.attrs['style'] = self.process_inline_style() @staticmethod def remove_white_if_no_bgcolor(style_, tag): @@ -76,7 +76,7 @@ class TagStyleConverter: processed style with counted indent """ - processed_style = ";".join(split_style) + processed_style = ";".join(split_style)+';' margin_left_regexp = re.compile( r"((margin-left|margin): *(-*\w+);*)") @@ -142,7 +142,7 @@ class TagStyleConverter: # 3. Duplicate styles check - if the tag had duplicate styles split_inline_style = self.duplicate_styles_check(split_inline_style) - # 4. Processing indents# + # 4. Processing indents inline_style: str = self.indents_processing(split_inline_style) return inline_style @@ -170,7 +170,7 @@ class TagStyleConverter: def change_attrs_with_corresponding_tags(self): # adds , , instead of styles - styles_to_remove = self.check_style_to_be_tag(self.style) + styles_to_remove = self.check_style_to_be_tag(self.tag_inline_style.attrs['style']) for i, (attr, value) in enumerate(styles_to_remove): self.tag_inline_style.attrs["style"] = self.tag_inline_style.attrs["style"]\ .replace(f"{attr}:{value};", "").strip() @@ -184,10 +184,10 @@ class TagStyleConverter: @staticmethod def wrap_span_in_tag_to_save_style_attrs(initial_tag): """Function designed to save style attrs that cannot be in tag.name -> span""" - dictkeys_pattern = re.compile("|".join(LiveCartaConfig.LIVECARTA_STYLES_CANT_BE_IN_TAG)) + dictkeys_pattern = re.compile("|".join(LiveCartaConfig.LIVECARTA_STYLES_CAN_BE_IN_TAG)) if re.findall(dictkeys_pattern, initial_tag.name) and initial_tag.attrs.get("style"): styles_can_be_in_tag = [style - for tag, styles in LiveCartaConfig.LIVECARTA_STYLES_CANT_BE_IN_TAG.items() + for tag, styles in LiveCartaConfig.LIVECARTA_STYLES_CAN_BE_IN_TAG.items() if re.match(tag, initial_tag.name) for style in styles] styles_cant_be_in_tag = [attr for attr in LIVECARTA_STYLE_ATTRS @@ -201,7 +201,7 @@ class TagStyleConverter: # if we find styles that cannot be in -> wrap them in span tag = BeautifulSoup(features="lxml").new_tag(f"{initial_tag.name}") style = "" - possible_attrs_regexp = [re.compile(fr"({style}: *(\w+);)") for style in styles_can_be_in_tag] + possible_attrs_regexp = [re.compile(fr"{style}: *\w+;") for style in styles_can_be_in_tag] for possible_attr_regexp in possible_attrs_regexp: has_style_attrs = re.search( possible_attr_regexp, span_style) diff --git a/src/livecarta_config.py b/src/livecarta_config.py index 31b549e..2cfafb6 100644 --- a/src/livecarta_config.py +++ b/src/livecarta_config.py @@ -117,7 +117,7 @@ class LiveCartaConfig: ("vertical-align", "super"): "sup" } - LIVECARTA_STYLES_CANT_BE_IN_TAG = { + LIVECARTA_STYLES_CAN_BE_IN_TAG = { "p": ["text-align", "text-indent", "border-bottom", "border-top"], "li": ["text-align", "list-style-type"], "ul": ["list-style-type"],