From dd49bfd76ccde155bd57d3434ff916be42b38314 Mon Sep 17 00:00:00 2001 From: Kibzik Date: Wed, 15 Mar 2023 20:44:37 +0300 Subject: [PATCH] Fix span wrapper processing --- src/inline_style_processor.py | 5 +++-- src/livecarta_config.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/inline_style_processor.py b/src/inline_style_processor.py index 06c5fae..6fc4aff 100644 --- a/src/inline_style_processor.py +++ b/src/inline_style_processor.py @@ -220,7 +220,7 @@ class InlineStyleProcessor: style = "" # Compile a list of regex patterns to match style attributes that can be in the tag 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 for possible_attr_regexp in possible_attrs_regexp: @@ -231,10 +231,11 @@ class InlineStyleProcessor: # Add the style attribute to the new element if it exists if style: tag.attrs["style"] = style + initial_tag.name = "span" # Set the "style" attribute of the initial tag to the remaining style attributes initial_tag.attrs["style"] = span_style # Wrap the new element around the initial tag and return it - initial_tag.wrap(tag) + initial_tag = initial_tag.wrap(tag) return initial_tag def convert_initial_tag(self) -> Tag: diff --git a/src/livecarta_config.py b/src/livecarta_config.py index 528c514..f13f597 100644 --- a/src/livecarta_config.py +++ b/src/livecarta_config.py @@ -30,12 +30,13 @@ class LiveCartaConfig: # 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-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"], "^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"] + "^ol$": ["list-style-type"] } # Dictionary mapping CSS style attribute names to names that should replace them