forked from LiveCarta/BookConverter
Create remove_extra_spaces() for style
This commit is contained in:
@@ -301,6 +301,20 @@ class TagStyleConverter:
|
||||
return clean_style
|
||||
|
||||
def preprocess_style(self):
|
||||
def remove_extra_spaces(style: str) -> List:
|
||||
# replace all spaces between '; & letter' to ';'
|
||||
style = re.sub(r"; *", ";", style)
|
||||
split_style = style.split(';')
|
||||
|
||||
# when we split style by ; and we have at the end ; that's why we have '' in list
|
||||
while '' in split_style:
|
||||
split_style.remove('')
|
||||
|
||||
# replace all spaces between ': & letter' to ':'
|
||||
split_style = [el.replace(
|
||||
re.search(r'(:\s*)', el).group(1), ':') for el in split_style]
|
||||
return split_style
|
||||
|
||||
ultimate_style = self.tag_with_ultimate_style.attrs.get('style') + ';'
|
||||
ultimate_style = self.remove_white_if_no_bgcolor(
|
||||
ultimate_style, self.tag_with_ultimate_style)
|
||||
@@ -308,29 +322,12 @@ class TagStyleConverter:
|
||||
'background:', 'background-color:')
|
||||
ultimate_style = ultimate_style.replace(
|
||||
'list-style-image', 'list-style-type')
|
||||
|
||||
split_ultimate_style = ultimate_style.replace('; ', ';').split(';')
|
||||
|
||||
# when we split style by ; and we have at the end ; that's why we have '' in list
|
||||
while '' in split_ultimate_style:
|
||||
split_ultimate_style.remove('')
|
||||
|
||||
# replace all spaces between ': & letter' to ':'
|
||||
split_ultimate_style = [el.replace(
|
||||
re.search(r'(:\s*)', el).group(1), ':') for el in split_ultimate_style]
|
||||
split_ultimate_style: List = remove_extra_spaces(ultimate_style)
|
||||
|
||||
if self.tag_with_inline_style.attrs.get('style'):
|
||||
inline_style = self.tag_with_inline_style.attrs['style']
|
||||
|
||||
split_inline_style = inline_style.replace('; ', ';').split(';')
|
||||
|
||||
# when we split style by ; and we have at the end ; that's why we have '' in list
|
||||
while '' in split_inline_style:
|
||||
split_inline_style.remove('')
|
||||
|
||||
# replace all spaces between ': & letter' to ':'
|
||||
split_inline_style = [el.replace(
|
||||
re.search(r'(:\s*)', el).group(1), ':') for el in split_inline_style]
|
||||
split_inline_style: List = remove_extra_spaces(inline_style)
|
||||
|
||||
# repetition check - if the tag had already had inline style that isn't in the css styles, add this to style parsed from css
|
||||
repeat_styles = list(set(split_ultimate_style)
|
||||
@@ -339,7 +336,7 @@ class TagStyleConverter:
|
||||
split_inline_style.remove(item)
|
||||
|
||||
if split_inline_style:
|
||||
# if inline style is not empty - start convert and add to ultimate style
|
||||
# if split_inline_style is not empty - start convert and add to ultimate style
|
||||
print('we enter repetition check', '\n')
|
||||
inline_style: str = self.process_indents_to_px(
|
||||
split_inline_style)
|
||||
|
||||
Reference in New Issue
Block a user