diff --git a/src/docx_converter/html_docx_preprocessor.py b/src/docx_converter/html_docx_preprocessor.py
index 425fa10..c264d17 100644
--- a/src/docx_converter/html_docx_preprocessor.py
+++ b/src/docx_converter/html_docx_preprocessor.py
@@ -113,13 +113,6 @@ class HTMLDocxPreprocessor:
elif color and color in LiveCartaConfig.COLORS_MAP:
font.attrs["style"] = f'color: {color};'
- if face is not None:
- face = re.sub(r",[\w,\- ]*$", "", face)
- if face != LiveCartaConfig.DEFAULT_FONT_NAME and LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.get(face):
- font.attrs["face"] = LiveCartaConfig.FONT_CORRESPONDANCE_TABLE[face]
- else:
- font.attrs["face"] = LiveCartaConfig.DEFAULT_FONT_NAME
-
if len(font.attrs) == 0:
font.unwrap()
diff --git a/src/epub_converter/css_preprocessing.py b/src/epub_converter/css_preprocessing.py
index 2e65880..0ad0ff7 100644
--- a/src/epub_converter/css_preprocessing.py
+++ b/src/epub_converter/css_preprocessing.py
@@ -78,7 +78,7 @@ def convert_indents_tag_values(size_value: str) -> str:
"""
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.
If property has empty list, it means that any value can be converted.
If property has not empty list, it means that only certain property-value combinations can be transformed.
"""
@@ -88,8 +88,7 @@ LIVECARTA_STYLE_ATTRS = {
"text-align": [x for x in LiveCartaConfig.ALIGN_STYLES if x != LiveCartaConfig.DEFAULT_ALIGN_STYLE],
"align": [],
"font": [],
- "font-family": [x for x in LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.keys()
- if x != LiveCartaConfig.DEFAULT_FONT_NAME],
+ "font-family": [],
"font-size": [],
"font-weight": ["bold", "600", "700", "800", "900"], #
"font-style": ["italic"], #
@@ -118,15 +117,14 @@ LIVECARTA_STYLE_ATTRS = {
Dictionary LIVECARTA_STYLE_ATTRS_MAPPING = { property: mapping function }
Warning, if LIVECARTA_STYLE_ATTRS is changed, LIVECARTA_STYLE_ATTRS_MAPPING should be updated
-to suit livecarta style convention.
+to suit LiveCarta style convention.
"""
LIVECARTA_STYLE_ATTRS_MAPPING = {
"text-indent": convert_indents_tag_values,
"font-variant": lambda x: x,
"text-align": lambda x: x,
"font": lambda x: "",
- "font-family": lambda x: LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.get(re.sub(r"^\s+|\s+$", "", x.title()))
- or LiveCartaConfig.FONT_CORRESPONDANCE_TABLE.get(re.sub(r"^\s+|\s+$", "", x)),
+ "font-family": lambda x: x,
"font-size": convert_tag_style_values,
"color": get_text_color,
"background-color": get_bg_color,
@@ -146,6 +144,15 @@ LIVECARTA_STYLE_ATTRS_MAPPING = {
}
+def style_conditions(style_value, style_name):
+ cleaned_value = style_value.replace("\"", "")
+ constraints_on_value = LIVECARTA_STYLE_ATTRS.get(
+ style_name)
+ value_not_in_possible_values_list = cleaned_value not in LIVECARTA_STYLE_ATTRS[
+ style_name]
+ return cleaned_value, constraints_on_value, value_not_in_possible_values_list
+
+
def update_inline_styles_to_livecarta_convention(split_style: list):
for i, style in enumerate(split_style):
style_name, style_value = style.split(":")
@@ -154,11 +161,8 @@ def update_inline_styles_to_livecarta_convention(split_style: list):
split_style[i] = ""
return split_style
- cleaned_value = style_value.replace("\"", "").split()[-1]
- constraints_on_value = LIVECARTA_STYLE_ATTRS.get(
- style_name)
- value_not_in_possible_values_list = cleaned_value not in LIVECARTA_STYLE_ATTRS[
- style_name]
+ cleaned_value, constraints_on_value, value_not_in_possible_values_list =\
+ style_conditions(style_value, style_name)
if constraints_on_value and value_not_in_possible_values_list:
# there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove from css file
split_style[i] = ""
@@ -172,7 +176,7 @@ def update_inline_styles_to_livecarta_convention(split_style: list):
def build_inline_style_content(style: str) -> str:
- """Build inline style with livecarta convention"""
+ """Build inline style with LiveCarta convention"""
# replace all spaces between "; & letter" to ";"
style = re.sub(r"; *", ";", style)
# when we split style by ";", last element of the list is "" - None
@@ -189,16 +193,15 @@ def build_inline_style_content(style: str) -> str:
def update_css_styles_to_livecarta_convention(css_rule: cssutils.css.CSSStyleRule,
style_type: cssutils.css.property.Property):
+ if style_type.name == "font-family":
+ pass
if style_type.name not in LIVECARTA_STYLE_ATTRS:
# property not in LIVECARTA_STYLE_ATTRS, remove from css file
css_rule.style[style_type.name] = ""
return
- cleaned_value = style_type.value.replace("\"", "")
- constraints_on_value = LIVECARTA_STYLE_ATTRS.get(
- style_type.name)
- value_not_in_possible_values_list = cleaned_value not in LIVECARTA_STYLE_ATTRS[
- style_type.name]
+ cleaned_value, constraints_on_value, value_not_in_possible_values_list =\
+ style_conditions(style_type.value, style_type.name)
if constraints_on_value and value_not_in_possible_values_list:
# there are constraints + value not in LIVECARTA_STYLE_ATTRS, remove from css file
css_rule.style[style_type.name] = ""
@@ -210,7 +213,7 @@ def update_css_styles_to_livecarta_convention(css_rule: cssutils.css.CSSStyleRul
def build_css_file_content(css_content: str) -> str:
- """Build css content with livecarta convention"""
+ """Build css content with LiveCarta convention"""
sheet = cssutils.parseString(css_content, validate=False)
for css_rule in sheet:
diff --git a/src/livecarta_config.py b/src/livecarta_config.py
index 9929cda..9a94545 100644
--- a/src/livecarta_config.py
+++ b/src/livecarta_config.py
@@ -23,20 +23,6 @@ class LiveCartaConfig:
FONT_CONVERT_RATIO = LIVECARTA_DEFAULT_FONT_SIZE /\
WORD_DEFAULT_FONT_SIZE
- FONT_CORRESPONDANCE_TABLE = {
- "Arial": "arial,helvetica,sans-serif",
- "Comic Sans MS": "comic sans ms,cursive",
- "Courier New": "courier new,courier,monospace",
- "Georgia": "georgia,serif",
- "Lucida Sans Unicode": "lucida sans unicode,lucida grande,sans-serif",
- "Tahoma": "tahoma,geneva,sans-serif",
- "Times New Roman": "times new roman,times,serif",
- "Trebuchet MS": "trebuchet ms,helvetica,sans-serif",
- "Verdana": "verdana,geneva,sans-serif",
- "monospace": "courier new,courier,monospace",
- "sans-serif": "arial,helvetica,sans-serif"
- }
-
COLORS_MAP = {
"#ffff00": "yellow",
"#00ff00": "darkYellow",
@@ -116,8 +102,8 @@ class LiveCartaConfig:
}
WRAP_TAGS_WITH_TABLE = {
- ("div",) :["width", "border", "bgcolor"],
- ("section", "blockquote",) : ("class", r"feature[1234]"),
+ ("div",): ["width", "border", "bgcolor"],
+ ("section", "blockquote",): ("class", r"feature[1234]"),
}
"""('what to replace', 'parent tag', 'child tag')"""