forked from LiveCarta/BookConverter
Fix bug: empty string in int
This commit is contained in:
@@ -66,17 +66,17 @@ def convert_indents(value):
|
|||||||
if has_style_attrs:
|
if has_style_attrs:
|
||||||
if has_style_attrs.group(1):
|
if has_style_attrs.group(1):
|
||||||
value = value.replace(has_style_attrs.group(1),
|
value = value.replace(has_style_attrs.group(1),
|
||||||
str(abs(int("".join(filter(str.isdigit, str(has_style_attrs.group(1))))) * 6)) +
|
str(abs(int("0" + "".join(filter(str.isdigit, str(has_style_attrs.group(1))))) * 6)) +
|
||||||
'px')
|
'px')
|
||||||
|
|
||||||
elif has_style_attrs.group(2):
|
elif has_style_attrs.group(2):
|
||||||
value = value.replace(has_style_attrs.group(2),
|
value = value.replace(has_style_attrs.group(2),
|
||||||
str(abs(int("".join(filter(str.isdigit, str(has_style_attrs.group(3))))) * 30)) +
|
str(abs(int("0" + "".join(filter(str.isdigit, str(has_style_attrs.group(3))))) * 30)) +
|
||||||
'px')
|
'px')
|
||||||
|
|
||||||
elif has_style_attrs.group(4):
|
elif has_style_attrs.group(4):
|
||||||
value = value.replace(has_style_attrs.group(4),
|
value = value.replace(has_style_attrs.group(4),
|
||||||
str(abs(int("".join(filter(str.isdigit, str(has_style_attrs.group(4))))))) + 'px')
|
str(abs(int("0" + "".join(filter(str.isdigit, str(has_style_attrs.group(4))))))) + 'px')
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +114,8 @@ LIVECARTA_STYLE_ATTRS = {
|
|||||||
'border-bottom': [],
|
'border-bottom': [],
|
||||||
'list-style-type': [],
|
'list-style-type': [],
|
||||||
'list-style-image': [],
|
'list-style-image': [],
|
||||||
'margin-left': []
|
'margin-left': [],
|
||||||
|
'margin-top': []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,7 +156,8 @@ LIVECARTA_STYLE_ATTRS_MAPPING = {
|
|||||||
'border-bottom': lambda x: x if x != '0' else '',
|
'border-bottom': lambda x: x if x != '0' else '',
|
||||||
'list-style-type': lambda x: x if x in list_types else 'disc',
|
'list-style-type': lambda x: x if x in list_types else 'disc',
|
||||||
'list-style-image': lambda x: 'disc',
|
'list-style-image': lambda x: 'disc',
|
||||||
'margin-left': convert_indents
|
'margin-left': convert_indents,
|
||||||
|
'margin-top': convert_indents
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -274,19 +276,19 @@ class TagStyleConverter:
|
|||||||
clean_style += item[0] + ': ' + item[1] + '; '
|
clean_style += item[0] + ': ' + item[1] + '; '
|
||||||
|
|
||||||
margin_left_regexp = re.compile(
|
margin_left_regexp = re.compile(
|
||||||
r'(margin-left:( *-*\w+);*)')
|
r'(margin-left: *(-*\w+);*)')
|
||||||
text_indent_regexp = re.compile(
|
text_indent_regexp = re.compile(
|
||||||
r'(text-indent:( *-*\w+);*)')
|
r'(text-indent: *(-*\w+);*)')
|
||||||
|
|
||||||
has_margin_left = re.search(margin_left_regexp, clean_style)
|
has_margin_left = re.search(margin_left_regexp, clean_style)
|
||||||
has_text_indent = re.search(text_indent_regexp, clean_style)
|
has_text_indent = re.search(text_indent_regexp, clean_style)
|
||||||
# formula_of_indent: indent = abs(margin_left - text_indent)
|
# formula_of_indent: indent = abs(margin_left - text_indent)
|
||||||
if has_margin_left:
|
if has_margin_left:
|
||||||
num_ml = abs(int("".join(
|
num_ml = abs(int("0" + "".join(
|
||||||
filter(str.isdigit, str(has_margin_left.group(2))))))
|
filter(str.isdigit, str(has_margin_left.group(2))))))
|
||||||
|
|
||||||
if has_text_indent:
|
if has_text_indent:
|
||||||
num_ti = abs(int("".join(
|
num_ti = abs(int("0" + "".join(
|
||||||
filter(str.isdigit, str(has_text_indent.group(2))))))
|
filter(str.isdigit, str(has_text_indent.group(2))))))
|
||||||
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
|
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
|
||||||
str(abs(num_ml - num_ti)) + 'px; ')
|
str(abs(num_ml - num_ti)) + 'px; ')
|
||||||
@@ -299,7 +301,7 @@ class TagStyleConverter:
|
|||||||
|
|
||||||
elif has_text_indent:
|
elif has_text_indent:
|
||||||
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
|
clean_style = clean_style.replace(has_text_indent.group(1), 'text-indent: ' +
|
||||||
str(abs(int("".join(
|
str(abs(int("0" + "".join(
|
||||||
filter(str.isdigit, str(has_text_indent.group(2))))))) + 'px; ')
|
filter(str.isdigit, str(has_text_indent.group(2))))))) + 'px; ')
|
||||||
return clean_style
|
return clean_style
|
||||||
return clean_style
|
return clean_style
|
||||||
@@ -309,8 +311,11 @@ class TagStyleConverter:
|
|||||||
""" Function to remove extra spaces in style to process clean_style """
|
""" Function to remove extra spaces in style to process clean_style """
|
||||||
# replace all spaces between '; & letter' to ';'
|
# replace all spaces between '; & letter' to ';'
|
||||||
style = re.sub(r"; *", ";", style)
|
style = re.sub(r"; *", ";", style)
|
||||||
split_style = style.split(';')
|
split_style: List = style.split(';')
|
||||||
|
# result = {}
|
||||||
|
# for list_item in split_style:
|
||||||
|
# key, val = list_item.split(":")
|
||||||
|
# result[key] = val
|
||||||
# when we split style by ; and we have at the end ; that's why we have '' in list
|
# when we split style by ; and we have at the end ; that's why we have '' in list
|
||||||
while '' in split_style:
|
while '' in split_style:
|
||||||
split_style.remove('')
|
split_style.remove('')
|
||||||
|
|||||||
Reference in New Issue
Block a user