Fix span wrapper processing

This commit is contained in:
Kibzik
2023-03-15 20:00:32 +03:00
parent b5ad043335
commit 047bfeca20
7 changed files with 82 additions and 75 deletions

View File

@@ -2,24 +2,18 @@ import re
class LiveCartaConfig:
"""Class of values that LiveCarta platform using and supports"""
# tag with inline style to be updated with style attribute
SUPPORTED_LEVELS = 5
SUPPORTED_HEADERS = {"h1", "h2", "h3", "h4", "h5"}
"""Class of values that LiveCarta platform supports"""
list_types = ["circle", "disc", "armenian", "decimal",
"decimal-leading-zero", "georgian", "lower-alpha", "lower-latin",
"lower-roman", "upper-alpha", "upper-latin", "upper-roman", "none"]
NUM_SUPPORTED_LEVELS = 5
SUPPORTED_HEADER_TAGS = {"h1", "h2", "h3", "h4", "h5"}
could_have_style_in_livecarta_regexp = re.compile(
"(^div$)|(^p$)|(^span$)|(^code$)|(^kbd$)|(^var$)|(^li$)|(^ul$)|(^ol$)|(^td$)|(^th$)|(^h[1-9]$)")
# Regular expression to match HTML tags that can have a style attribute
REGEX_TAGS_WITH_STYLE_ATTR = re.compile(
"(^div$)|(^p$)|(^span$)|(^code$)|(^kbd$)|(^var$)|(^li$)|(^ul$)|(^ol$)|(^td$)|(^th$)|(^h[1-9]$)"
)
"""
LIVECARTA_STYLE_ATTRS_SHOULD_BE_TAG = { (property, value): tag }
<p style="font-weight:600> foo </p> -> <p><strong>foo</strong></p>
"""
LIVECARTA_STYLE_ATTRS_SHOULD_BE_TAG = {
# Dictionary mapping CSS style attribute-value pairs to HTML tags
STYLE_ATTRS_TO_TAGS = {
("font-weight", "bold"): "strong",
("font-weight", "600"): "strong",
("font-weight", "700"): "strong",
@@ -33,28 +27,26 @@ class LiveCartaConfig:
("vertical-align", "super"): "sup"
}
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"],
"ol": ["list-style-type"],
r"(^h[1-9]$)": ["list-style-type"]
# Dictionary mapping HTML tags to CSS style attributes that can be contained within them
TAGS_TO_STYLE_ATTRS_CAN_BE_IN_TAG = {
"^p$": ["text-align", "text-indent", "border-bottom", "border-top", "border-left", "border-right",
"background-color"],
"^li$": ["text-align", "list-style-type"],
"^ul$": ["list-style-type"],
"^ol$": ["list-style-type"],
r"(^h[1-9]$)": ["list-style-type", "border-bottom", "border-top", "border-left", "border-right",
"background-color", "color"]
}
"""
Dictionary LIVECARTA_STYLE_ATTRS_REPLACE = { css property: css property to replace with }
"""
LIVECARTA_STYLE_ATTRS_REPLACE = {
# Dictionary mapping CSS style attribute names to names that should replace them
STYLE_ATTR_TO_REPLACEMENT = {
"list-style": "list-style-type",
}
"""
Dictionary LIVECARTA_STYLE_ATTRS = { css property: value }
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.
"""
LIVECARTA_STYLE_ATTRS = {
# Dictionary mapping CSS style attribute names to lists of allowed values
# If an empty list is provided, any value is allowed for the attribute
# If a non-empty list is provided, only values in the list are allowed for the attribute
STYLE_ATTR_TO_VALUE_LIMIT = {
"align": [],
"font": [],
"font-family": [],