Fix bag 4622 + indents

This commit is contained in:
Kiryl
2021-09-24 16:29:48 +03:00
parent 55ca366583
commit 63b6a3bda3
5 changed files with 15 additions and 16 deletions

View File

@@ -231,8 +231,21 @@ class TagStyleConverter:
style = style.replace('list-style-image', 'list-style-type')
# if tag had already had inline style, add this to style parsed from css
if self.tag.attrs.get('style') and self.tag.attrs['style'] not in style:
style += self.tag.attrs['style']
# hot_fix
negative_text_indent_regexp = re.compile(r'((text-indent:( *-\w+%*);) *(margin-left:( *\w+%*);))|(text-indent:( *-\w+%*);)')
inline_style = self.tag.attrs['style']
has_inline_style_attrs = re.search(negative_text_indent_regexp, inline_style)
has_css_style_attrs = re.search(negative_text_indent_regexp, style)
if has_inline_style_attrs:
if has_inline_style_attrs.group(1):
inline_style = inline_style.replace(has_inline_style_attrs.group(1), 'text-indent: ' + has_inline_style_attrs.group(5))
style = style.replace(has_css_style_attrs.group(1), '')
if has_inline_style_attrs.group(6):
inline_style = inline_style.replace(has_inline_style_attrs.group(6), '')
style = style.replace(has_css_style_attrs.group(6), '')
style += inline_style
return style