epub converter: add table processing, class removal

This commit is contained in:
shirshasa
2021-04-29 16:23:46 +03:00
parent 0a9124c046
commit d21b11f99a
2 changed files with 55 additions and 4 deletions

View File

@@ -76,6 +76,12 @@ LIVECARTA_STYLE_ATTRS = {
'vertical-align': ['super'], # <sup>
'color': [],
'background-color': [],
'width': [],
'border-top-width': [],
'border-right-width': [],
'border-left-width': [],
'border-bottom-width': [],
'border': []
}
"""
@@ -85,7 +91,7 @@ Warning, if LIVECARTA_STYLE_ATTRS is changed, LIVECARTA_STYLE_ATTRS_MAPPING shou
to suit livecarta style convention.
"""
LIVECARTA_STYLE_ATTRS_MAPPING = {
'text-indent': lambda x: LawCartaConfig.INDENT,
'text-indent': lambda x: LawCartaConfig.INDENT if x != '0' else '',
'font-variant': lambda x: x,
'text-align': lambda x: x,
'font': lambda x: '',
@@ -93,6 +99,10 @@ LIVECARTA_STYLE_ATTRS_MAPPING = {
'font-size': convert_font_size,
'color': lambda x: LawCartaConfig.HTML42LIVECARTA_COLORS.get(str2color_name(x), ''),
'background-color': lambda x: LawCartaConfig.HTML42LIVECARTA_COLORS.get(str2color_name(x), ''),
'border-top-width': lambda x: x if x != '0' else '',
'border-right-width': lambda x: x if x != '0' else '',
'border-left-width': lambda x: x if x != '0' else '',
'border-bottom-width': lambda x: x if x != '0' else '',
}
"""
@@ -162,7 +172,7 @@ 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$)' + h_regex))):
for i, x in enumerate(soup1.find_all(re.compile('(^p$)|(^span$)|(^li$)|(^ul$)|(^ol$)|(^td$)|' + h_regex))):
x.attrs['livecarta_id'] = i
livecarta_tmp_ids.append(i)