forked from LiveCarta/BookConverter
Add lines with style 'border-bottom'
This commit is contained in:
@@ -75,6 +75,7 @@ def convert_indents(value):
|
||||
value = value.replace(has_style_attrs.group(4),
|
||||
str(abs(int("".join(filter(str.isdigit, str(has_style_attrs.group(4))))))) + 'px')
|
||||
return value
|
||||
|
||||
"""
|
||||
LIVECARTA_STYLE_ATTRS = { css property: value }
|
||||
|
||||
@@ -130,7 +131,6 @@ def get_text_color(x):
|
||||
color = color if color not in ['#000000', '#000', 'black'] else ''
|
||||
return color
|
||||
|
||||
|
||||
LIVECARTA_STYLE_ATTRS_MAPPING = {
|
||||
'text-indent': convert_indents,
|
||||
'font-variant': lambda x: x,
|
||||
@@ -293,7 +293,7 @@ class TagStyleConverter:
|
||||
ultimate_style = ultimate_style.replace('background:', 'background-color:')
|
||||
ultimate_style = ultimate_style.replace('list-style-image', 'list-style-type')
|
||||
|
||||
split_ultimate_style = ultimate_style.replace(' ', '').split(';') # make for repetition check and convert to px
|
||||
split_ultimate_style = ultimate_style.split(';') # make for repetition check and convert to px
|
||||
|
||||
# check for another ; in style string in preprocess_style()
|
||||
while '' in split_ultimate_style:
|
||||
@@ -303,7 +303,7 @@ class TagStyleConverter:
|
||||
if self.tag_with_initial_style.attrs.get('style'):
|
||||
|
||||
initial_style = self.tag_with_initial_style.attrs['style']
|
||||
split_initial_style = initial_style.replace(' ', '').split(';')
|
||||
split_initial_style = initial_style.split(';')
|
||||
|
||||
# check for another ; in style string in preprocess_style()
|
||||
while '' in split_initial_style:
|
||||
@@ -356,7 +356,7 @@ class TagStyleConverter:
|
||||
@staticmethod
|
||||
def wrap_span_in_p_to_save_style_attrs(tag):
|
||||
styles_cant_be_in_p = [attr for attr in LIVECARTA_STYLE_ATTRS
|
||||
if attr not in ['text-align', 'text-indent']]
|
||||
if attr not in ['text-align', 'text-indent', 'border-bottom']]
|
||||
|
||||
if tag.name == 'p' and tag.attrs.get('style'):
|
||||
styles_to_be_saved = [attr in tag.attrs.get('style') for attr in styles_cant_be_in_p]
|
||||
@@ -365,7 +365,7 @@ class TagStyleConverter:
|
||||
p_tag = BeautifulSoup(features='lxml').new_tag('p')
|
||||
span_style = tag.attrs['style']
|
||||
p_style = ''
|
||||
possible_p_attrs_regexp = re.compile(r'(text-align:( *\w+);*)|(text-indent:( *\w+);*)')
|
||||
possible_p_attrs_regexp = re.compile(r'(text-align:( *\w+);*)|(text-indent:( *\w+);*)|(border-bottom:( *\w+);*)')
|
||||
for i in range(span_style.count(';') + 1):
|
||||
has_p_style_attrs = re.search(possible_p_attrs_regexp, span_style)
|
||||
if has_p_style_attrs:
|
||||
@@ -375,6 +375,9 @@ class TagStyleConverter:
|
||||
if has_p_style_attrs.group(3):
|
||||
p_style += has_p_style_attrs.group(3)
|
||||
span_style = span_style.replace(has_p_style_attrs.group(3), '')
|
||||
if has_p_style_attrs.group(5):
|
||||
p_style += span_style
|
||||
span_style = span_style.replace(span_style, '')
|
||||
|
||||
p_tag.attrs['style'] = p_style
|
||||
|
||||
@@ -388,7 +391,7 @@ class TagStyleConverter:
|
||||
def add_span_to_save_style_attrs_in_li(t):
|
||||
if t.name == 'li' and t.attrs.get('style'):
|
||||
styles_cant_be_in_li = [attr for attr in LIVECARTA_STYLE_ATTRS if
|
||||
attr not in ['text-align', 'list-style-type']]
|
||||
attr not in ['text-align', 'list-style-type', 'border-bottom']]
|
||||
|
||||
check = [attr in t.attrs.get('style') for attr in styles_cant_be_in_li]
|
||||
if any(check):
|
||||
|
||||
Reference in New Issue
Block a user