epub converter: fix wrapping <p> with bg color

This commit is contained in:
shirshasa
2021-07-02 12:32:36 +03:00
parent fba4303dd7
commit 7dd4cebde1

View File

@@ -219,7 +219,7 @@ def add_inline_style_to_html_soup(soup1, css_text):
return style_
def wrap_p_if_bg_color(t):
if (t.name == 'p') and ('background' in t.attrs.get('style')):
if (t.name == 'p' and t.attrs.get('style')) and ('background' in t.attrs.get('style')):
t.name = 'span'
t.wrap( BeautifulSoup(features='lxml').new_tag('p'))
@@ -246,23 +246,24 @@ def add_inline_style_to_html_soup(soup1, css_text):
new_tags[-1].wrap(new_tag)
new_tags.append(new_tag)
top_tag = tag
if to_remove:
style = style.strip()
tmp_attrs = tag.attrs.copy()
tag.attrs = {}
span_tag = BeautifulSoup(features='lxml').new_tag(tag_initial_name)
span_tag.attrs = tmp_attrs
top_tag = BeautifulSoup(features='lxml').new_tag(tag_initial_name)
top_tag.attrs = tmp_attrs
if style:
span_tag.attrs['style'] = style
del span_tag.attrs['livecarta_id']
top_tag.attrs['style'] = style
del top_tag.attrs['livecarta_id']
new_tags[-1].wrap(span_tag)
new_tags[-1].wrap(top_tag)
else:
tag.attrs['style'] = style
del tag.attrs['livecarta_id']
wrap_p_if_bg_color(tag)
wrap_p_if_bg_color(top_tag)
else:
del tag.attrs['livecarta_id']