epub converter: fix removing <p>

This commit is contained in:
shirshasa
2021-07-05 09:00:40 +03:00
parent b435db052b
commit d563e08465

View File

@@ -220,10 +220,14 @@ def add_inline_style_to_html_soup(soup1, css_text):
style_ = style_.replace('color:white;', '') style_ = style_.replace('color:white;', '')
return style_ return style_
def wrap_p_if_bg_color(t): def wrap_p_to_save_style_attrs(t):
if (t.name == 'p' and t.attrs.get('style')) and ('background' in t.attrs.get('style')): styles_cant_be_in_p = [attr for attr in LIVECARTA_STYLE_ATTRS if attr not in ['text-align', 'text-indent']]
t.name = 'span'
t.wrap( BeautifulSoup(features='lxml').new_tag('p')) if t.name == 'p' and t.attrs.get('style'):
check = [attr in t.attrs.get('style') for attr in styles_cant_be_in_p]
if any(check):
t.name = 'span'
t.wrap( BeautifulSoup(features='lxml').new_tag('p'))
for i in livecarta_tmp_ids: for i in livecarta_tmp_ids:
tag = soup1.find(attrs={'livecarta_id': i}) tag = soup1.find(attrs={'livecarta_id': i})