forked from LiveCarta/BookConverter
epub converter: prettify
This commit is contained in:
@@ -147,25 +147,18 @@ def update_property_to_livecarta_convention(rule, property_):
|
||||
if property_.name not in LIVECARTA_STYLE_ATTRS:
|
||||
# property not in LIVECARTA_STYLE_ATTRS, remove from css file
|
||||
rule.style[property_.name] = ''
|
||||
return
|
||||
|
||||
elif LIVECARTA_STYLE_ATTRS.get(property_.name):
|
||||
# check property value to decide weather to remove or not the property_
|
||||
cleaned_property = property_.value.replace('\"', '')
|
||||
if cleaned_property in LIVECARTA_STYLE_ATTRS[property_.name]:
|
||||
|
||||
if property_.name in LIVECARTA_STYLE_ATTRS_MAPPING:
|
||||
# apply transformation
|
||||
func = LIVECARTA_STYLE_ATTRS_MAPPING[property_.name]
|
||||
rule.style[property_.name] = func(cleaned_property)
|
||||
else:
|
||||
# property + value not in LIVECARTA_STYLE_ATTRS, remove from css file
|
||||
rule.style[property_.name] = ''
|
||||
cleaned_value = property_.value.replace('\"', '')
|
||||
there_are_constraints_on_value = LIVECARTA_STYLE_ATTRS.get(property_.name)
|
||||
value_not_in_possible_values_list = cleaned_value not in LIVECARTA_STYLE_ATTRS[property_.name]
|
||||
if there_are_constraints_on_value and value_not_in_possible_values_list:
|
||||
# property + value not in LIVECARTA_STYLE_ATTRS, remove from css file
|
||||
rule.style[property_.name] = ''
|
||||
else:
|
||||
# property can have any value
|
||||
if property_.name in LIVECARTA_STYLE_ATTRS_MAPPING:
|
||||
func = LIVECARTA_STYLE_ATTRS_MAPPING[property_.name]
|
||||
cleaned_property = property_.value.replace('\"', '')
|
||||
rule.style[property_.name] = func(cleaned_property)
|
||||
rule.style[property_.name] = func(cleaned_value)
|
||||
|
||||
|
||||
def clean_css(css):
|
||||
@@ -182,7 +175,9 @@ def clean_css(css):
|
||||
def add_inline_style_to_html_soup(soup1, css_text):
|
||||
livecarta_tmp_ids = []
|
||||
h_regex = f'(^h[{LawCartaConfig.SUPPORTED_LEVELS + 1}-9]$)'
|
||||
for i, x in enumerate(soup1.find_all(re.compile('(^p$)|(^span$)|(^li$)|(^ul$)|(^ol$)|(^td$)|(^th$)|' + h_regex))):
|
||||
could_have_style_in_livecarta_regexp = re.compile('(^p$)|(^span$)|(^li$)|(^ul$)|(^ol$)|(^td$)|(^th$)|' + h_regex)
|
||||
elements_with_possible_style_attr = soup1.find_all(could_have_style_in_livecarta_regexp)
|
||||
for i, x in enumerate(elements_with_possible_style_attr):
|
||||
x.attrs['livecarta_id'] = i
|
||||
livecarta_tmp_ids.append(i)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user