Fix span wrapper processing

This commit is contained in:
Kibzik
2023-03-15 20:44:37 +03:00
parent 047bfeca20
commit dd49bfd76c
2 changed files with 8 additions and 6 deletions

View File

@@ -220,7 +220,7 @@ class InlineStyleProcessor:
style = "" style = ""
# Compile a list of regex patterns to match style attributes that can be in the tag # Compile a list of regex patterns to match style attributes that can be in the tag
possible_attrs_regexp = [ possible_attrs_regexp = [
re.compile(fr"({style}: *[#a-zA-Z\d]+;)", re.IGNORECASE) for style in styles_can_be_in_tag re.compile(fr"({style}:[^;]*;)", re.IGNORECASE) for style in styles_can_be_in_tag
] ]
# Iterate over the list of regex patterns and search for matching style attributes # Iterate over the list of regex patterns and search for matching style attributes
for possible_attr_regexp in possible_attrs_regexp: for possible_attr_regexp in possible_attrs_regexp:
@@ -231,10 +231,11 @@ class InlineStyleProcessor:
# Add the style attribute to the new <tag> element if it exists # Add the style attribute to the new <tag> element if it exists
if style: if style:
tag.attrs["style"] = style tag.attrs["style"] = style
initial_tag.name = "span"
# Set the "style" attribute of the initial tag to the remaining style attributes # Set the "style" attribute of the initial tag to the remaining style attributes
initial_tag.attrs["style"] = span_style initial_tag.attrs["style"] = span_style
# Wrap the new <tag> element around the initial tag and return it # Wrap the new <tag> element around the initial tag and return it
initial_tag.wrap(tag) initial_tag = initial_tag.wrap(tag)
return initial_tag return initial_tag
def convert_initial_tag(self) -> Tag: def convert_initial_tag(self) -> Tag:

View File

@@ -30,12 +30,13 @@ class LiveCartaConfig:
# Dictionary mapping HTML tags to CSS style attributes that can be contained within them # Dictionary mapping HTML tags to CSS style attributes that can be contained within them
TAGS_TO_STYLE_ATTRS_CAN_BE_IN_TAG = { TAGS_TO_STYLE_ATTRS_CAN_BE_IN_TAG = {
"^p$": ["text-align", "text-indent", "border-bottom", "border-top", "border-left", "border-right", "^p$": ["text-align", "text-indent", "border-bottom", "border-top", "border-left", "border-right",
"background-color"], "background-color"],
r"(^h[1-9]$)": ["list-style-type", "border-bottom", "border-top", "border-left", "border-right",
"background-color"],
"^div$": ["border-bottom", "border-top", "border-left", "border-right", "background-color"],
"^li$": ["text-align", "list-style-type"], "^li$": ["text-align", "list-style-type"],
"^ul$": ["list-style-type"], "^ul$": ["list-style-type"],
"^ol$": ["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 mapping CSS style attribute names to names that should replace them # Dictionary mapping CSS style attribute names to names that should replace them