forked from LiveCarta/BookConverter
epub converter: fix wrapping <p> with bg color
This commit is contained in:
@@ -219,7 +219,7 @@ def add_inline_style_to_html_soup(soup1, css_text):
|
|||||||
return style_
|
return style_
|
||||||
|
|
||||||
def wrap_p_if_bg_color(t):
|
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.name = 'span'
|
||||||
t.wrap( BeautifulSoup(features='lxml').new_tag('p'))
|
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[-1].wrap(new_tag)
|
||||||
new_tags.append(new_tag)
|
new_tags.append(new_tag)
|
||||||
|
|
||||||
|
top_tag = tag
|
||||||
if to_remove:
|
if to_remove:
|
||||||
style = style.strip()
|
style = style.strip()
|
||||||
tmp_attrs = tag.attrs.copy()
|
tmp_attrs = tag.attrs.copy()
|
||||||
tag.attrs = {}
|
tag.attrs = {}
|
||||||
|
|
||||||
span_tag = BeautifulSoup(features='lxml').new_tag(tag_initial_name)
|
top_tag = BeautifulSoup(features='lxml').new_tag(tag_initial_name)
|
||||||
span_tag.attrs = tmp_attrs
|
top_tag.attrs = tmp_attrs
|
||||||
if style:
|
if style:
|
||||||
span_tag.attrs['style'] = style
|
top_tag.attrs['style'] = style
|
||||||
del span_tag.attrs['livecarta_id']
|
del top_tag.attrs['livecarta_id']
|
||||||
|
|
||||||
new_tags[-1].wrap(span_tag)
|
new_tags[-1].wrap(top_tag)
|
||||||
else:
|
else:
|
||||||
tag.attrs['style'] = style
|
tag.attrs['style'] = style
|
||||||
del tag.attrs['livecarta_id']
|
del tag.attrs['livecarta_id']
|
||||||
|
|
||||||
wrap_p_if_bg_color(tag)
|
wrap_p_if_bg_color(top_tag)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
del tag.attrs['livecarta_id']
|
del tag.attrs['livecarta_id']
|
||||||
|
|||||||
Reference in New Issue
Block a user