forked from LiveCarta/BookConverter
Fix span wrapper processing
This commit is contained in:
@@ -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 <tag> 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 <tag> 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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user