forked from LiveCarta/BookConverter
Add support of list-style-type
This commit is contained in:
@@ -41,6 +41,13 @@ class LiveCartaConfig:
|
|||||||
r"(^h[1-9]$)": ["list-style-type"]
|
r"(^h[1-9]$)": ["list-style-type"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Dictionary LIVECARTA_STYLE_ATTRS_REPLACE = { css property: css property to replace with }
|
||||||
|
"""
|
||||||
|
LIVECARTA_STYLE_ATTRS_REPLACE = {
|
||||||
|
"list-style": "list-style-type",
|
||||||
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Dictionary LIVECARTA_STYLE_ATTRS = { css property: value }
|
Dictionary LIVECARTA_STYLE_ATTRS = { css property: value }
|
||||||
Style properties that can be used to fit LiveCarta css style convention.
|
Style properties that can be used to fit LiveCarta css style convention.
|
||||||
@@ -84,6 +91,6 @@ class LiveCartaConfig:
|
|||||||
"border-right": [],
|
"border-right": [],
|
||||||
"border-left": [],
|
"border-left": [],
|
||||||
"border-bottom": [],
|
"border-bottom": [],
|
||||||
"list-style-type": [],
|
"list-style-type": ["circle", "disc", "square", "decimal"],
|
||||||
"list-style-image": [],
|
"list-style-image": [],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class StyleReader:
|
|||||||
"border-right": self.convert_tag_style_values,
|
"border-right": self.convert_tag_style_values,
|
||||||
"border-left": self.convert_tag_style_values,
|
"border-left": self.convert_tag_style_values,
|
||||||
"border-bottom": self.convert_tag_style_values,
|
"border-bottom": self.convert_tag_style_values,
|
||||||
"list-style-type": lambda x: x if x in LiveCartaConfig.list_types else "disc",
|
"list-style-type": lambda x: x,
|
||||||
"list-style-image": lambda x: "disc"
|
"list-style-image": lambda x: "disc"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,11 +104,14 @@ class StyleReader:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clean_value(style_value: str, style_name: str):
|
def clean_value(style_value: str, style_name: str):
|
||||||
|
def replace_str(str, lst):
|
||||||
|
return next((elem for elem in lst if elem in str), str)
|
||||||
cleaned_value = style_value.replace("\"", "")
|
cleaned_value = style_value.replace("\"", "")
|
||||||
if style_name == 'font-family':
|
if style_name == 'font-family':
|
||||||
for symbol in ["+", "*", ".", "%", "?", "$", "^", "[", "]"]:
|
for symbol in ["+", "*", ".", "%", "?", "$", "^", "[", "]"]:
|
||||||
cleaned_value = re.sub(
|
cleaned_value = re.sub(
|
||||||
re.escape(f"{symbol}"), rf"\\{symbol}", cleaned_value)
|
re.escape(f"{symbol}"), rf"\\{symbol}", cleaned_value)
|
||||||
|
cleaned_value = replace_str(cleaned_value, LiveCartaConfig.LIVECARTA_STYLE_ATTRS[style_name])
|
||||||
return cleaned_value
|
return cleaned_value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -122,6 +125,8 @@ class StyleReader:
|
|||||||
def update_inline_styles_to_livecarta_convention(self, split_style: list) -> list:
|
def update_inline_styles_to_livecarta_convention(self, split_style: list) -> list:
|
||||||
try:
|
try:
|
||||||
for i, style in reversed(list(enumerate(split_style))):
|
for i, style in reversed(list(enumerate(split_style))):
|
||||||
|
if style.split(":")[0] in LiveCartaConfig.LIVECARTA_STYLE_ATTRS_REPLACE:
|
||||||
|
style = LiveCartaConfig.LIVECARTA_STYLE_ATTRS_REPLACE[style.split(":")[0]] + ":" + style.split(":")[1]
|
||||||
style_name, style_value = style.split(":")
|
style_name, style_value = style.split(":")
|
||||||
if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS:
|
if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS:
|
||||||
# property not in LIVECARTA_STYLE_ATTRS, remove
|
# property not in LIVECARTA_STYLE_ATTRS, remove
|
||||||
@@ -189,11 +194,13 @@ class StyleReader:
|
|||||||
|
|
||||||
def update_css_styles_to_livecarta_convention(self, css_rule: cssutils.css.CSSStyleRule,
|
def update_css_styles_to_livecarta_convention(self, css_rule: cssutils.css.CSSStyleRule,
|
||||||
style_type: cssutils.css.property.Property):
|
style_type: cssutils.css.property.Property):
|
||||||
|
if style_type.name in LiveCartaConfig.LIVECARTA_STYLE_ATTRS_REPLACE:
|
||||||
|
# attributes to replace
|
||||||
|
style_type.name = LiveCartaConfig.LIVECARTA_STYLE_ATTRS_REPLACE[style_type.name]
|
||||||
if style_type.name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS:
|
if style_type.name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS:
|
||||||
# property not in LIVECARTA_STYLE_ATTRS, remove from css file
|
# property not in LIVECARTA_STYLE_ATTRS, remove from css file
|
||||||
css_rule.style[style_type.name] = ""
|
css_rule.style[style_type.name] = ""
|
||||||
return
|
return
|
||||||
|
|
||||||
cleaned_value = self.clean_value(style_type.value, style_type.name)
|
cleaned_value = self.clean_value(style_type.value, style_type.name)
|
||||||
if all(self.style_conditions(cleaned_value, style_type.name)):
|
if all(self.style_conditions(cleaned_value, style_type.name)):
|
||||||
# there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove from css file
|
# there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove from css file
|
||||||
|
|||||||
Reference in New Issue
Block a user