add background to divs

This commit is contained in:
Kiryl
2021-10-06 19:29:13 +03:00
parent b767c5901c
commit e693a77182
2 changed files with 14 additions and 5 deletions

View File

@@ -244,8 +244,9 @@ class TagStyleConverter:
return style_
@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_style = ''
for item in split_style:
item = item.split(':')
@@ -295,7 +296,7 @@ class TagStyleConverter:
# check for another ; in style string in preprocess_style()
while '' in split_ultimate_style:
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'):
@@ -314,9 +315,8 @@ class TagStyleConverter:
if split_initial_style:
# if initial style is not empty - start convert and add to ultimate style
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
return ultimate_style
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";', '')
livecarta_tmp_ids = []
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)
for i, x in enumerate(tags_with_possible_style_attr):
x.attrs['livecarta_id'] = i