forked from LiveCarta/BookConverter
Fix style problem with span
This commit is contained in:
@@ -16,7 +16,7 @@ class TagStyleConverter:
|
||||
def __init__(self, tag_inline_style):
|
||||
# tag with inline style + style parsed from css file
|
||||
self.tag_inline_style = tag_inline_style
|
||||
self.style = self.process_inline_style()
|
||||
self.tag_inline_style.attrs['style'] = self.process_inline_style()
|
||||
|
||||
@staticmethod
|
||||
def remove_white_if_no_bgcolor(style_, tag):
|
||||
@@ -76,7 +76,7 @@ class TagStyleConverter:
|
||||
processed style with counted indent
|
||||
|
||||
"""
|
||||
processed_style = ";".join(split_style)
|
||||
processed_style = ";".join(split_style)+';'
|
||||
|
||||
margin_left_regexp = re.compile(
|
||||
r"((margin-left|margin): *(-*\w+);*)")
|
||||
@@ -142,7 +142,7 @@ class TagStyleConverter:
|
||||
# 3. Duplicate styles check - if the tag had duplicate styles
|
||||
split_inline_style = self.duplicate_styles_check(split_inline_style)
|
||||
|
||||
# 4. Processing indents#
|
||||
# 4. Processing indents
|
||||
inline_style: str = self.indents_processing(split_inline_style)
|
||||
return inline_style
|
||||
|
||||
@@ -170,7 +170,7 @@ class TagStyleConverter:
|
||||
|
||||
def change_attrs_with_corresponding_tags(self):
|
||||
# adds <strong>, <u>, <sup> instead of styles
|
||||
styles_to_remove = self.check_style_to_be_tag(self.style)
|
||||
styles_to_remove = self.check_style_to_be_tag(self.tag_inline_style.attrs['style'])
|
||||
for i, (attr, value) in enumerate(styles_to_remove):
|
||||
self.tag_inline_style.attrs["style"] = self.tag_inline_style.attrs["style"]\
|
||||
.replace(f"{attr}:{value};", "").strip()
|
||||
@@ -184,10 +184,10 @@ class TagStyleConverter:
|
||||
@staticmethod
|
||||
def wrap_span_in_tag_to_save_style_attrs(initial_tag):
|
||||
"""Function designed to save style attrs that cannot be in tag.name -> span"""
|
||||
dictkeys_pattern = re.compile("|".join(LiveCartaConfig.LIVECARTA_STYLES_CANT_BE_IN_TAG))
|
||||
dictkeys_pattern = re.compile("|".join(LiveCartaConfig.LIVECARTA_STYLES_CAN_BE_IN_TAG))
|
||||
if re.findall(dictkeys_pattern, initial_tag.name) and initial_tag.attrs.get("style"):
|
||||
styles_can_be_in_tag = [style
|
||||
for tag, styles in LiveCartaConfig.LIVECARTA_STYLES_CANT_BE_IN_TAG.items()
|
||||
for tag, styles in LiveCartaConfig.LIVECARTA_STYLES_CAN_BE_IN_TAG.items()
|
||||
if re.match(tag, initial_tag.name)
|
||||
for style in styles]
|
||||
styles_cant_be_in_tag = [attr for attr in LIVECARTA_STYLE_ATTRS
|
||||
@@ -201,7 +201,7 @@ class TagStyleConverter:
|
||||
# if we find styles that cannot be in <tag.name> -> wrap them in span
|
||||
tag = BeautifulSoup(features="lxml").new_tag(f"{initial_tag.name}")
|
||||
style = ""
|
||||
possible_attrs_regexp = [re.compile(fr"({style}: *(\w+);)") for style in styles_can_be_in_tag]
|
||||
possible_attrs_regexp = [re.compile(fr"{style}: *\w+;") for style in styles_can_be_in_tag]
|
||||
for possible_attr_regexp in possible_attrs_regexp:
|
||||
has_style_attrs = re.search(
|
||||
possible_attr_regexp, span_style)
|
||||
|
||||
@@ -117,7 +117,7 @@ class LiveCartaConfig:
|
||||
("vertical-align", "super"): "sup"
|
||||
}
|
||||
|
||||
LIVECARTA_STYLES_CANT_BE_IN_TAG = {
|
||||
LIVECARTA_STYLES_CAN_BE_IN_TAG = {
|
||||
"p": ["text-align", "text-indent", "border-bottom", "border-top"],
|
||||
"li": ["text-align", "list-style-type"],
|
||||
"ul": ["list-style-type"],
|
||||
|
||||
Reference in New Issue
Block a user