forked from LiveCarta/BookConverter
add background to divs
This commit is contained in:
@@ -244,8 +244,9 @@ class TagStyleConverter:
|
|||||||
return style_
|
return style_
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_indents_in_px(split_style: list) -> str:
|
def process_indents_to_px(split_style: list) -> str:
|
||||||
# clean with convert_indents() style string and make new clean_style
|
# clean with convert_indents() style string and make new clean_style
|
||||||
|
|
||||||
clean_style = ''
|
clean_style = ''
|
||||||
for item in split_style:
|
for item in split_style:
|
||||||
item = item.split(':')
|
item = item.split(':')
|
||||||
@@ -295,7 +296,7 @@ class TagStyleConverter:
|
|||||||
# check for another ; in style string in preprocess_style()
|
# check for another ; in style string in preprocess_style()
|
||||||
while '' in split_ultimate_style:
|
while '' in split_ultimate_style:
|
||||||
split_ultimate_style.remove('')
|
split_ultimate_style.remove('')
|
||||||
ultimate_style: str = self.process_indents_in_px(split_ultimate_style)
|
ultimate_style: str = self.process_indents_to_px(split_ultimate_style)
|
||||||
|
|
||||||
if self.tag_with_initial_style.attrs.get('style'):
|
if self.tag_with_initial_style.attrs.get('style'):
|
||||||
|
|
||||||
@@ -314,9 +315,8 @@ class TagStyleConverter:
|
|||||||
if split_initial_style:
|
if split_initial_style:
|
||||||
# if initial style is not empty - start convert and add to ultimate style
|
# if initial style is not empty - start convert and add to ultimate style
|
||||||
print('we enter repetition check', '\n')
|
print('we enter repetition check', '\n')
|
||||||
initial_style: str = self.process_indents_in_px(split_initial_style)
|
initial_style: str = self.process_indents_to_px(split_initial_style)
|
||||||
ultimate_style += initial_style
|
ultimate_style += initial_style
|
||||||
|
|
||||||
return ultimate_style
|
return ultimate_style
|
||||||
|
|
||||||
def change_attrs_with_corresponding_tags(self):
|
def change_attrs_with_corresponding_tags(self):
|
||||||
@@ -452,7 +452,7 @@ def convert_html_soup_with_css_style(html_soup: BeautifulSoup, css_text: str):
|
|||||||
css_text = css_text.replace('@namespace epub "http://www.idpf.org/2007/ops";', '')
|
css_text = css_text.replace('@namespace epub "http://www.idpf.org/2007/ops";', '')
|
||||||
livecarta_tmp_ids = []
|
livecarta_tmp_ids = []
|
||||||
h_regex = f'(^h[1-9]$)'
|
h_regex = f'(^h[1-9]$)'
|
||||||
could_have_style_in_livecarta_regexp = re.compile('(^p$)|(^span$)|(^li$)|(^ul$)|(^ol$)|(^td$)|(^th$)|' + h_regex)
|
could_have_style_in_livecarta_regexp = re.compile('(^div$)|(^p$)|(^span$)|(^li$)|(^ul$)|(^ol$)|(^td$)|(^th$)|' + h_regex)
|
||||||
tags_with_possible_style_attr = html_soup.find_all(could_have_style_in_livecarta_regexp)
|
tags_with_possible_style_attr = html_soup.find_all(could_have_style_in_livecarta_regexp)
|
||||||
for i, x in enumerate(tags_with_possible_style_attr):
|
for i, x in enumerate(tags_with_possible_style_attr):
|
||||||
x.attrs['livecarta_id'] = i
|
x.attrs['livecarta_id'] = i
|
||||||
|
|||||||
@@ -316,6 +316,15 @@ def unwrap_structural_tags(body_tag):
|
|||||||
elif div_class in ['C441', 'C816']:
|
elif div_class in ['C441', 'C816']:
|
||||||
_add_table_to_abc_books(div, border='solid #6e6e70 1px', bg_color='#e7e7e8')
|
_add_table_to_abc_books(div, border='solid #6e6e70 1px', bg_color='#e7e7e8')
|
||||||
|
|
||||||
|
if div.attrs.get('style'):
|
||||||
|
if 'background-color' in div.attrs['style']:
|
||||||
|
end_index = div.attrs['style'].find('background-color') + len('background-color')
|
||||||
|
start_index_of_color = end_index + 2
|
||||||
|
bg_color = div.attrs['style'][start_index_of_color:start_index_of_color+7]
|
||||||
|
_add_table_to_abc_books(div, border='', bg_color=bg_color)
|
||||||
|
|
||||||
|
if div.attrs.get('style') == '':
|
||||||
|
del div.attrs['style']
|
||||||
if div.contents:
|
if div.contents:
|
||||||
is_not_struct_tag = [child.name not in structural_tags_names for child in div.contents]
|
is_not_struct_tag = [child.name not in structural_tags_names for child in div.contents]
|
||||||
if all(is_not_struct_tag):
|
if all(is_not_struct_tag):
|
||||||
|
|||||||
Reference in New Issue
Block a user