This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BookConverter/src/livecarta_config.py
2022-06-24 17:12:21 +03:00

133 lines
4.2 KiB
Python

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"}
HEADERS_LEVELS = {"h1", "h2", "h3",
"h4", "h5", "h6", "h7", "h8", "h9"}
DEFAULT_ALIGN_STYLE = "left"
ALIGN_STYLES = ["justify", "right", "center", "left"]
# Main constant values
DEFAULT_FONT_NAME = "Times New Roman"
WORD_DEFAULT_FONT_SIZE = 11
LIVECARTA_DEFAULT_FONT_SIZE = 18
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",
"#00ffff": "cyan",
"#ff00ff": "magenta",
"#0000ff": "blue",
"#ff0000": "red",
"#000080": "darkBlue",
"#008080": "darkCyan",
"#008000": "green",
"#800080": "darkMagenta",
"#808000": "darkGreen",
"#c0c0c0": "lightGray",
"#ffffff": "white",
"#800000": "#800000",
"#808080": "#808080"
}
HTML42LIVECARTA_COLORS = {
"yellow": "yellow",
"lime": "green",
"aqua": "cyan",
"fuchsia": "magenta",
"blue": "blue",
"red": "red",
"navy": "darkBlue",
"teal": "darkCyan",
"green": "darkGreen",
"purple": "darkMagenta",
"olive": "darkYellow",
"silver": "lightGray",
"white": "white",
"maroon": "darkRed", # "#800000",
"gray": "darkGray",
"grey": "darkGray",
}
INDENT = "30px"
list_types = ["circle", "disc", "armenian", "decimal",
"decimal-leading-zero", "georgian", "lower-alpha", "lower-latin",
"lower-roman", "upper-alpha", "upper-latin", "upper-roman", "none"]
structural_tags_names = [
"div", "section", "article", "main", "body", "html", "aside",
"canvas", "data", "figure", "footer", "iframe", "span", "p"
]
could_have_style_in_livecarta_regexp = 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 = {
("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"
}
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"]
}
WRAP_TAGS_WITH_TABLE = {
("div",) :["width", "border", "bgcolor"],
("section", "blockquote",) : ("class", r"feature[1234]"),
}
REPLACE_REGEX_WITH_LIVECARTA_CORRESPOND_TAGS = {
(r"^h[6-9]$", "^figure$", "^section$", "^div$"): "p",
("^aside$",): "blockquote",
("^header$", "^footer$"): "span",
("^b$",): "strong",
}
TAGS_TO_UNWRAP = [
"section", "article", "figcaption", "main", "body", "html",
]