comment duplicate_styles_check cause of transform

This commit is contained in:
Kiryl
2022-07-08 18:36:09 +03:00
parent 1926377a34
commit 7d5c1bfdf2
2 changed files with 13 additions and 14 deletions

View File

@@ -229,7 +229,6 @@ class HtmlEpubPreprocessor:
Chapter Tag with inserted tags
"""
def insert(tag, tag_to_insert):
# insert all items that was in tag to subtag and remove from tag
for content in reversed(tag.contents):

View File

@@ -48,15 +48,18 @@ class TagInlineStyleProcessor:
style_ = style_.replace("color:white;", "")
return style_
@staticmethod
def duplicate_styles_check(split_style: list) -> list:
style_name2style_value = {}
for list_item in split_style:
key, val = list_item.split(":")
if val not in style_name2style_value.keys():
style_name2style_value[key] = val
split_style = [k + ":" + v for k, v in style_name2style_value.items()]
return split_style
# @staticmethod
# def duplicate_styles_check(split_style: list) -> list:
# style_name2style_value = {}
# # {key: val for for list_item in split_style}
# splitstrs = (list_item.split(":") for list_item in split_style)
# d = {key: val for key, val in splitstrs}
# for list_item in split_style:
# key, val = list_item.split(":")
# if key not in style_name2style_value.keys():
# style_name2style_value[key] = val
# split_style = [k + ":" + v for k, v in style_name2style_value.items()]
# return split_style
@staticmethod
def indents_processing(split_style: list) -> str:
@@ -130,16 +133,13 @@ class TagInlineStyleProcessor:
inline_style, self.tag_inline_style)
inline_style = inline_style.replace(
"list-style-image", "list-style-type")
# 2. Create list of styles from inline style
# replace all spaces between "; & letter" to ";"
style = re.sub(r"; *", ";", inline_style)
# when we split style by ";", last element of the list is "" - None (remove it)
split_inline_style: list = list(filter(None, style.split(";")))
# 3. Duplicate styles check - if the tag had duplicate styles
split_inline_style = self.duplicate_styles_check(split_inline_style)
# split_inline_style = self.duplicate_styles_check(split_inline_style)
# 4. Processing indents
inline_style: str = self.indents_processing(split_inline_style)
return inline_style