import re class LiveCartaConfig: """Class of values that LiveCarta platform supports""" NUM_SUPPORTED_LEVELS = 5 SUPPORTED_HEADER_TAGS = {"h1", "h2", "h3", "h4", "h5"} # 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]$)" ) # 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", ("font-weight", "800"): "strong", ("font-weight", "900"): "strong", ("font-style", "italic"): "i", ("text-decoration", "underline"): "u", ("text-decoration", "line-through"): "s", ("text-decoration-line", "underline"): "u", ("text-decoration-line", "line-through"): "s", ("vertical-align", "super"): "sup" } # 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", "background"], r"(^h[1-9]$)": ["list-style-type", "border-bottom", "border-top", "border-left", "border-right", "background-color", "background"], "^li$": ["text-align", "list-style-type"], "^ul$": ["list-style-type"], "^ol$": ["list-style-type"] } # Dictionary mapping CSS style attribute names to names that should replace them STYLE_ATTR_TO_REPLACEMENT = { "list-style": "list-style-type", } # 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": [], "font-size": [], "font-variant": ["small-caps"], "font-weight": ["bold", "600", "700", "800", "900"], # "font-style": ["italic"], # "text-decoration": ["underline", "line-through"], # , "text-decoration-line": ["underline", "line-through"], # , "text-transform": [], "text-align": ["justify", "right", "center"], "text-indent": [], "margin": [], "margin-top": [], "margin-right": [], "margin-left": [], "margin-bottom": [], "padding": [], "padding-top": [], "padding-right": [], "padding-left": [], "padding-bottom": [], "vertical-align": ["super"], # "color": [], "background-color": [], "background": [], "width": [], "border": [], "border-top-width": [], "border-right-width": [], "border-left-width": [], "border-bottom-width": [], "border-top": [], "border-right": [], "border-left": [], "border-bottom": [], "list-style-type": ["circle", "disc", "square", "decimal"], "list-style-image": [], }